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 Http1ServerSession.h
27
28 Description:
29
30
31 ****************************************************************************/
32
33 #pragma once
34
35 #include "P_Net.h"
36
37 #include "HttpConnectionCount.h"
38 #include "HttpProxyAPIEnums.h"
39 #include "PoolableSession.h"
40
41 class HttpSM;
42 class MIOBuffer;
43 class IOBufferReader;
44
45 enum {
46 HTTP_SS_MAGIC_ALIVE = 0x0123FEED,
47 HTTP_SS_MAGIC_DEAD = 0xDEADFEED,
48 };
49
50 class Http1ServerSession : public PoolableSession
51 {
52 using self_type = Http1ServerSession;
53 using super_type = PoolableSession;
54
55 public:
Http1ServerSession()56 Http1ServerSession() : super_type() {}
57 Http1ServerSession(self_type const &) = delete;
58 self_type &operator=(self_type const &) = delete;
59 ~Http1ServerSession() = default;
60
61 ////////////////////
62 // Methods
63 void release(ProxyTransaction *) override;
64 void destroy() override;
65 void free() override;
66
67 // VConnection Methods
68 void do_io_close(int lerrno = -1) override;
69
70 // ProxySession Methods
71 int get_transact_count() const override;
72 const char *get_protocol_string() const override;
73 void increment_current_active_connections_stat() override;
74 void decrement_current_active_connections_stat() override;
75 void new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOBufferReader *reader) override;
76 void start() override;
77
78 void enable_outbound_connection_tracking(OutboundConnTrack::Group *group);
79 IOBufferReader *get_reader() override;
80 void attach_hostname(const char *hostname);
81 IpEndpoint const &get_server_ip() const;
82
83 ////////////////////
84 // Variables
85
86 int transact_count = 0;
87
88 // Used to determine whether the session is for parent proxy
89 // it is session to origin server
90 // We need to determine whether a closed connection was to
91 // close parent proxy to update the
92 // proxy.process.http.current_parent_proxy_connections
93 bool to_parent_proxy = false;
94
95 // The ServerSession owns the following buffer which use
96 // for parsing the headers. The server session needs to
97 // own the buffer so we can go from a keep-alive state
98 // to being acquired and parsing the header without
99 // changing the buffer we are doing I/O on. We can
100 // not change the buffer for I/O without issuing a
101 // an asynchronous cancel on NT
102 MIOBuffer *read_buffer = nullptr;
103
104 private:
105 int magic = HTTP_SS_MAGIC_DEAD;
106
107 IOBufferReader *buf_reader = nullptr;
108 };
109
110 extern ClassAllocator<Http1ServerSession, true> httpServerSessionAllocator;
111
112 ////////////////////////////////////////////
113 // INLINE
114
115 inline void
attach_hostname(const char * hostname)116 Http1ServerSession::attach_hostname(const char *hostname)
117 {
118 if (CRYPTO_HASH_ZERO == hostname_hash) {
119 CryptoContext().hash_immediate(hostname_hash, (unsigned char *)hostname, strlen(hostname));
120 }
121 }
122
123 inline IOBufferReader *
get_reader()124 Http1ServerSession::get_reader()
125 {
126 return buf_reader;
127 };
128