1 /** @file
2 
3   Http1Transaction.cc - The Transaction class for Http1*
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22  */
23 
24 #include "Http1Transaction.h"
25 #include "Http1ClientSession.h"
26 #include "HttpSM.h"
27 
28 void
release(IOBufferReader * r)29 Http1Transaction::release(IOBufferReader *r)
30 {
31   // Must set this inactivity count here rather than in the session because the state machine
32   // is not available then
33   MgmtInt ka_in = _sm->t_state.txn_conf->keep_alive_no_activity_timeout_in;
34   set_inactivity_timeout(HRTIME_SECONDS(ka_in));
35 
36   _proxy_ssn->clear_session_active();
37   _proxy_ssn->ssn_last_txn_time = Thread::get_hrtime();
38 
39   // Make sure that the state machine is returning
40   //  correct buffer reader
41   ink_assert(r == _reader);
42   if (r != _reader) {
43     this->do_io_close();
44   } else {
45     super_type::release(r);
46   }
47 }
48 
49 void
destroy()50 Http1Transaction::destroy() // todo make ~Http1Transaction()
51 {
52   _sm = nullptr;
53 }
54 
55 void
transaction_done()56 Http1Transaction::transaction_done()
57 {
58   if (_proxy_ssn) {
59     static_cast<Http1ClientSession *>(_proxy_ssn)->release_transaction();
60   }
61 }
62 
63 void
reenable(VIO * vio)64 Http1Transaction::reenable(VIO *vio)
65 {
66   _proxy_ssn->reenable(vio);
67 }
68 
69 bool
allow_half_open() const70 Http1Transaction::allow_half_open() const
71 {
72   bool config_allows_it = (_sm) ? _sm->t_state.txn_conf->allow_half_open > 0 : true;
73   if (config_allows_it) {
74     // Check with the session to make sure the underlying transport allows the half open scenario
75     return static_cast<Http1ClientSession *>(_proxy_ssn)->allow_half_open();
76   }
77   return false;
78 }
79 
80 void
increment_client_transactions_stat()81 Http1Transaction::increment_client_transactions_stat()
82 {
83   HTTP_INCREMENT_DYN_STAT(http_current_client_transactions_stat);
84 }
85 
86 void
decrement_client_transactions_stat()87 Http1Transaction::decrement_client_transactions_stat()
88 {
89   HTTP_DECREMENT_DYN_STAT(http_current_client_transactions_stat);
90 }
91 
92 // Implement VConnection interface.
93 VIO *
do_io_read(Continuation * c,int64_t nbytes,MIOBuffer * buf)94 Http1Transaction::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf)
95 {
96   return _proxy_ssn->do_io_read(c, nbytes, buf);
97 }
98 VIO *
do_io_write(Continuation * c,int64_t nbytes,IOBufferReader * buf,bool owner)99 Http1Transaction::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner)
100 {
101   return _proxy_ssn->do_io_write(c, nbytes, buf, owner);
102 }
103 
104 void
do_io_close(int lerrno)105 Http1Transaction::do_io_close(int lerrno)
106 {
107   _proxy_ssn->do_io_close(lerrno);
108   // this->destroy(); Parent owns this data structure.  No need for separate destroy.
109 }
110 
111 void
do_io_shutdown(ShutdownHowTo_t howto)112 Http1Transaction::do_io_shutdown(ShutdownHowTo_t howto)
113 {
114   _proxy_ssn->do_io_shutdown(howto);
115 }
116 
117 void
set_active_timeout(ink_hrtime timeout_in)118 Http1Transaction::set_active_timeout(ink_hrtime timeout_in)
119 {
120   if (_proxy_ssn)
121     _proxy_ssn->set_active_timeout(timeout_in);
122 }
123 void
set_inactivity_timeout(ink_hrtime timeout_in)124 Http1Transaction::set_inactivity_timeout(ink_hrtime timeout_in)
125 {
126   if (_proxy_ssn)
127     _proxy_ssn->set_inactivity_timeout(timeout_in);
128 }
129 void
cancel_inactivity_timeout()130 Http1Transaction::cancel_inactivity_timeout()
131 {
132   if (_proxy_ssn)
133     _proxy_ssn->cancel_inactivity_timeout();
134 }
135 //
136 int
get_transaction_id() const137 Http1Transaction::get_transaction_id() const
138 {
139   // For HTTP/1 there is only one on-going transaction at a time per session/connection.  Therefore, the transaction count can be
140   // presumed not to increase during the lifetime of a transaction, thus this function will return a consistent unique transaction
141   // identifier.
142   //
143   return _proxy_ssn->get_transact_count();
144 }
145