16 m_HTTPServer(a_HTTPServer),
33 SendData(fmt::format(FMT_STRING(
"HTTP/1.1 {} {}\r\n"), a_StatusCode, a_Response));
34 SendData(fmt::format(FMT_STRING(
"Content-Length: {}\r\n\r\n"), a_Response));
35 SendData(a_Response.data(), a_Response.size());
46 SendData(fmt::format(FMT_STRING(
"HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: Basic realm=\"{}\"\r\nContent-Length: 0\r\n\r\n"), a_Realm));
71 SendData(fmt::format(
"{0:x}\r\n", a_Size));
161 if (Split.size() < 2)
169 m_CurrentRequest = std::make_unique<cHTTPIncomingRequest>(Split[0], Split[1]);
234 m_Link->Send(a_Data, a_Size);
std::shared_ptr< cTCPLink > cTCPLinkPtr
AStringVector StringSplit(const AString &str, const AString &delim)
Split the string at any of the listed delimiters.
Stores outgoing response headers and serializes them to an HTTP data stream.
void AppendToData(AString &a_DataStream) const
Appends the response to the specified datastream - response line and headers.
void Reset(void)
Resets the parser to the initial state, so that a new request can be parsed.
size_t Parse(const char *a_Data, size_t a_Size)
Parses the incoming data and calls the appropriate callbacks.
void NewRequest(cHTTPServerConnection &a_Connection, cHTTPIncomingRequest &a_Request)
Called by cHTTPServerConnection when it finishes parsing the request header.
void RequestBody(cHTTPServerConnection &a_Connection, cHTTPIncomingRequest &a_Request, const void *a_Data, size_t a_Size)
Called by cHTTPConenction when it receives more data for the request body.
void RequestFinished(cHTTPServerConnection &a_Connection, cHTTPIncomingRequest &a_Request)
Called by cHTTPServerConnection when it detects that the request has finished (all of its body has be...
virtual void OnFirstLine(const AString &a_FirstLine) override
Called when the first line of the request or response is fully parsed.
cTCPLinkPtr m_Link
The network link attached to this connection.
cHTTPServerConnection(cHTTPServer &a_HTTPServer)
Creates a new instance, connected to the specified HTTP server instance.
virtual void OnHeadersFinished(void) override
Called when all the headers have been parsed.
void Terminate(void)
Terminates the connection; finishes any request being currently processed.
virtual void OnBodyFinished(void) override
Called when the entire body has been reported by OnBodyData().
virtual void OnBodyData(const void *a_Data, size_t a_Size) override
Called for each chunk of the incoming body data.
cHTTPMessageParser m_Parser
The parser responsible for reading the requests.
void SendNeedAuth(const AString &a_Realm)
Sends the "401 unauthorized" reply together with instructions on authorizing, using the specified rea...
virtual ~cHTTPServerConnection() override
virtual void OnRemoteClosed(void) override
The socket has been closed for any reason.
cHTTPServer & m_HTTPServer
The parent webserver that is to be notified of events on this connection.
virtual void OnHeaderLine(const AString &a_Key, const AString &a_Value) override
Called when a single header line is parsed.
void FinishResponse(void)
Indicates that the current response is finished, gets ready for receiving another request (HTTP 1....
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg) override
An error has occurred on the socket.
virtual void OnReceivedData(const char *a_Data, size_t a_Size) override
Data is received from the client.
std::unique_ptr< cHTTPIncomingRequest > m_CurrentRequest
The request being currently received Valid only between having parsed the headers and finishing recei...
void SendStatusAndReason(int a_StatusCode, const AString &a_Reason)
Sends HTTP status code together with a_Reason (used for HTTP errors).
virtual void OnLinkCreated(cTCPLinkPtr a_Link) override
The link instance has been created, remember it.
void Send(const cHTTPOutgoingResponse &a_Response)
Sends the headers contained in a_Response.
virtual void SendData(const void *a_Data, size_t a_Size)
Called to send raw data over the link.