From d0b9e817956a57389f17a3d8e00df51cbe8cc309 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 27 Sep 2013 19:34:46 +0200 Subject: Split cHTTPConnection implementation into a separate file. --- source/HTTPServer/HTTPServer.h | 68 ++---------------------------------------- 1 file changed, 2 insertions(+), 66 deletions(-) (limited to 'source/HTTPServer/HTTPServer.h') diff --git a/source/HTTPServer/HTTPServer.h b/source/HTTPServer/HTTPServer.h index 9287a79e8..fd4782267 100644 --- a/source/HTTPServer/HTTPServer.h +++ b/source/HTTPServer/HTTPServer.h @@ -18,80 +18,16 @@ // fwd: -class cHTTPServer; class cHTTPMessage; class cHTTPRequest; class cHTTPResponse; +class cHTTPConnection; +typedef std::vector cHTTPConnections; -class cHTTPConnection : - public cSocketThreads::cCallback -{ -public: - - enum eState - { - wcsRecvHeaders, ///< Receiving request headers (m_CurrentRequest == NULL) - wcsRecvBody, ///< Receiving request body (m_CurrentRequest is valid) - wcsRecvIdle, ///< Has received the entire body, waiting to send the response (m_CurrentRequest == NULL) - wcsSendingResp, ///< Sending response body (m_CurrentRequest == NULL) - wcsInvalid, ///< The request was malformed, the connection is closing - } ; - - cHTTPConnection(cHTTPServer & a_HTTPServer); - - /// Sends HTTP status code together with a_Reason (used for HTTP errors) - void SendStatusAndReason(int a_StatusCode, const AString & a_Reason); - - /// Sends the headers contained in a_Response - void Send(const cHTTPResponse & a_Response); - - /// Sends the data as the response (may be called multiple times) - void Send(const void * a_Data, int a_Size); - - /// Sends the data as the response (may be called multiple times) - void Send(const AString & a_Data) { Send(a_Data.data(), a_Data.size()); } - - /// Finishes sending current response, gets ready for receiving another request (HTTP 1.1 keepalive) - void FinishResponse(void); - -protected: - typedef std::map cNameValueMap; - - /// The parent webserver that is to be notified of events on this connection - cHTTPServer & m_HTTPServer; - - /// All the incoming data until the entire request header is parsed - AString m_IncomingHeaderData; - - /// Status in which the request currently is - eState m_State; - - /// Data that is queued for sending, once the socket becomes writable - AString m_OutgoingData; - - /// The request being currently received (valid only between having parsed the headers and finishing receiving the body) - cHTTPRequest * m_CurrentRequest; - - - /// Parses the header in m_IncomingData until the specified end mark - void ParseHeader(size_t a_IdxEnd); - - /// Sends the response status and headers. Transition from wrsRecvBody to wrsSendingResp. - void SendRespHeaders(void); - - // cSocketThreads::cCallback overrides: - virtual void DataReceived (const char * a_Data, int a_Size) override; // Data is received from the client - virtual void GetOutgoingData(AString & a_Data) override; // Data can be sent to client - virtual void SocketClosed (void) override; // The socket has been closed for any reason -} ; - -typedef std::vector cHTTPConnections; - - class cHTTPServer : -- cgit v1.2.3