1 /*
2  * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_SRC_SERVERS_HTTP1SERVER_H
10 #define SQUID_SRC_SERVERS_HTTP1SERVER_H
11 
12 #include "servers/forward.h"
13 
14 namespace Http
15 {
16 namespace One
17 {
18 
19 /// Manages a connection from an HTTP/1 or HTTP/0.9 client.
20 class Server: public ConnStateData
21 {
22     CBDATA_CLASS(Server);
23 
24 public:
25     Server(const MasterXaction::Pointer &xact, const bool beHttpsServer);
~Server()26     virtual ~Server() {}
27 
28     void readSomeHttpData();
29 
30 protected:
31     /* ConnStateData API */
32     virtual Http::Stream *parseOneRequest();
33     virtual void processParsedRequest(Http::StreamPointer &context);
34     virtual void handleReply(HttpReply *rep, StoreIOBuffer receivedData);
35     virtual bool writeControlMsgAndCall(HttpReply *rep, AsyncCall::Pointer &call);
36     virtual time_t idleTimeout() const;
37 
38     /* BodyPipe API */
39     virtual void noteMoreBodySpaceAvailable(BodyPipe::Pointer);
40     virtual void noteBodyConsumerAborted(BodyPipe::Pointer);
41 
42     /* AsyncJob API */
43     virtual void start();
44 
45     void proceedAfterBodyContinuation(Http::StreamPointer context);
46 
47 private:
48     void processHttpRequest(Http::Stream *const context);
49     void handleHttpRequestData();
50 
51     /// Handles parsing results. May generate and deliver an error reply
52     /// to the client if parsing is failed, or parses the url and build the
53     /// HttpRequest object using parsing results.
54     /// Return false if parsing is failed, true otherwise.
55     bool buildHttpRequest(Http::StreamPointer &context);
56 
57     void setReplyError(Http::StreamPointer &context, HttpRequest::Pointer &request, const HttpRequestMethod& method, err_type requestError, Http::StatusCode errStatusCode, const char *requestErrorBytes);
58 
59     Http1::RequestParserPointer parser_;
60     HttpRequestMethod method_; ///< parsed HTTP method
61 
62     /// temporary hack to avoid creating a true HttpsServer class
63     const bool isHttpsServer;
64 };
65 
66 } // namespace One
67 } // namespace Http
68 
69 #endif /* SQUID_SRC_SERVERS_HTTP1SERVER_H */
70 
71