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 enum {
47   HTTP_CS_MAGIC_ALIVE = 0x0123FEED,
48   HTTP_CS_MAGIC_DEAD  = 0xDEADFEED,
49 };
50 
51 class HttpSM;
52 class Http1ClientSession : public ProxySession
53 {
54 public:
55   typedef ProxySession super; ///< Parent type.
56   Http1ClientSession();
57   ~Http1ClientSession() = default;
58 
59   // Implement ProxySession interface.
60   void new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOBufferReader *reader) override;
61   void start() override;
62   void release(ProxyTransaction *trans) override; // Indicate we are done with a transaction
63   void release_transaction();
64   void destroy() override;
65   void free() override;
66 
67   bool attach_server_session(PoolableSession *ssession, bool transaction_done = true) override;
68 
69   // Implement VConnection interface.
70   void do_io_close(int lerrno = -1) override;
71 
72   // Accessor Methods
73   bool allow_half_open() const;
74   void set_half_close_flag(bool flag) override;
75   bool get_half_close_flag() const override;
76   bool is_chunked_encoding_supported() const override;
77   int get_transact_count() const override;
78   virtual bool is_outbound_transparent() const;
79 
80   PoolableSession *get_server_session() const override;
81   const char *get_protocol_string() const override;
82 
83   void increment_current_active_connections_stat() override;
84   void decrement_current_active_connections_stat() override;
85 
86 private:
87   Http1ClientSession(Http1ClientSession &);
88 
89   void new_transaction();
90 
91   int state_keep_alive(int event, void *data);
92   int state_slave_keep_alive(int event, void *data);
93   int state_wait_for_close(int event, void *data);
94 
95   enum C_Read_State {
96     HCS_INIT,
97     HCS_ACTIVE_READER,
98     HCS_KEEP_ALIVE,
99     HCS_HALF_CLOSED,
100     HCS_CLOSED,
101   };
102 
103   int magic          = HTTP_CS_MAGIC_DEAD;
104   int transact_count = 0;
105   bool half_close    = false;
106   bool conn_decrease = false;
107 
108   MIOBuffer *read_buffer  = nullptr;
109   IOBufferReader *_reader = nullptr;
110 
111   C_Read_State read_state = HCS_INIT;
112 
113   VIO *ka_vio       = nullptr;
114   VIO *slave_ka_vio = nullptr;
115 
116   PoolableSession *bound_ss = nullptr;
117 
118   int released_transactions = 0;
119 
120   int64_t read_from_early_data = 0;
121 
122 public:
123   // Link<Http1ClientSession> debug_link;
124   LINK(Http1ClientSession, debug_link);
125 
126   /// Set outbound connection to transparent.
127   bool f_outbound_transparent = false;
128 
129   Http1Transaction trans;
130 };
131 
132 extern ClassAllocator<Http1ClientSession, true> http1ClientSessionAllocator;
133