1 /** @file
2 
3   A brief file description
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 /****************************************************************************
25 
26    Http1ClientSession.h
27 
28    Description:
29 
30  ****************************************************************************/
31 
32 #pragma once
33 
34 #include "P_Net.h"
35 #include "InkAPIInternal.h"
36 #include "HTTP.h"
37 #include "HttpConfig.h"
38 #include "IPAllow.h"
39 #include "ProxySession.h"
40 #include "Http1Transaction.h"
41 
42 #ifdef USE_HTTP_DEBUG_LISTS
43 extern ink_mutex debug_cs_list_mutex;
44 #endif
45 
46 class HttpSM;
47 class Http1ServerSession;
48 
49 class Http1ClientSession : public ProxySession
50 {
51 public:
52   typedef ProxySession super; ///< Parent type.
53   Http1ClientSession();
54 
55   // Implement ProxySession interface.
56   void new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOBufferReader *reader) override;
57   void start() override;
58   void release(ProxyTransaction *trans) override; // Indicate we are done with a transaction
59   void release_transaction();
60   void destroy() override;
61   void free() override;
62 
63   void attach_server_session(Http1ServerSession *ssession, bool transaction_done = true) override;
64 
65   // Implement VConnection interface.
66   VIO *do_io_read(Continuation *c, int64_t nbytes = INT64_MAX, MIOBuffer *buf = nullptr) override;
67   VIO *do_io_write(Continuation *c = nullptr, int64_t nbytes = INT64_MAX, IOBufferReader *buf = nullptr,
68                    bool owner = false) override;
69 
70   void do_io_close(int lerrno = -1) override;
71   void do_io_shutdown(ShutdownHowTo_t howto) override;
72   void reenable(VIO *vio) override;
73 
74   // Accessor Methods
75   bool allow_half_open() const;
76   void set_half_close_flag(bool flag) override;
77   bool get_half_close_flag() const override;
78   bool is_chunked_encoding_supported() const override;
79   NetVConnection *get_netvc() const override;
80   int get_transact_count() const override;
81   virtual bool is_outbound_transparent() const;
82 
83   Http1ServerSession *get_server_session() const override;
84   void set_active_timeout(ink_hrtime timeout_in) override;
85   void set_inactivity_timeout(ink_hrtime timeout_in) override;
86   void cancel_inactivity_timeout() override;
87   const char *get_protocol_string() const override;
88 
89   void increment_current_active_client_connections_stat() override;
90   void decrement_current_active_client_connections_stat() override;
91 
92   bool support_sni() const override;
93 
94 private:
95   Http1ClientSession(Http1ClientSession &);
96 
97   void new_transaction();
98 
99   int state_keep_alive(int event, void *data);
100   int state_slave_keep_alive(int event, void *data);
101   int state_wait_for_close(int event, void *data);
102 
103   enum C_Read_State {
104     HCS_INIT,
105     HCS_ACTIVE_READER,
106     HCS_KEEP_ALIVE,
107     HCS_HALF_CLOSED,
108     HCS_CLOSED,
109   };
110 
111   NetVConnection *client_vc = nullptr;
112   int magic                 = HTTP_SS_MAGIC_DEAD;
113   int transact_count        = 0;
114   bool half_close           = false;
115   bool conn_decrease        = false;
116 
117   MIOBuffer *read_buffer  = nullptr;
118   IOBufferReader *_reader = nullptr;
119 
120   C_Read_State read_state = HCS_INIT;
121 
122   VIO *ka_vio       = nullptr;
123   VIO *slave_ka_vio = nullptr;
124 
125   Http1ServerSession *bound_ss = nullptr;
126 
127   int released_transactions = 0;
128 
129   int64_t read_from_early_data = 0;
130 
131 public:
132   // Link<Http1ClientSession> debug_link;
133   LINK(Http1ClientSession, debug_link);
134 
135   /// Set outbound connection to transparent.
136   bool f_outbound_transparent = false;
137 
138   Http1Transaction trans;
139 };
140 
141 extern ClassAllocator<Http1ClientSession> http1ClientSessionAllocator;
142