18 m_CurrentRequest(nullptr)
39 SendData(
Printf(
"HTTP/1.1 %d %s\r\n", a_StatusCode, a_Response.c_str()));
40 SendData(
Printf(
"Content-Length: %u\r\n\r\n", static_cast<unsigned>(a_Response.size())));
41 SendData(a_Response.data(), a_Response.size());
52 SendData(
Printf(
"HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: Basic realm=\"%s\"\r\nContent-Length: 0\r\n\r\n", a_Realm.c_str()));
77 SendData(fmt::format(
"{0:x}\r\n", a_Size));
167 if (split.size() < 2)
233 m_Link->Send(a_Data, a_Size);
cHTTPMessageParser m_Parser
The parser responsible for reading the requests.
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 AppendToData(AString &a_DataStream) const
Appends the response to the specified datastream - response line and headers.
void NewRequest(cHTTPServerConnection &a_Connection, cHTTPIncomingRequest &a_Request)
Called by cHTTPServerConnection when it finishes parsing the request header.
Provides storage for an incoming HTTP request.
cHTTPServerConnection(cHTTPServer &a_HTTPServer)
Creates a new instance, connected to the specified HTTP server instance.
virtual void OnHeaderLine(const AString &a_Key, const AString &a_Value) override
Called when a single header line is parsed.
Stores outgoing response headers and serializes them to an HTTP data stream.
void Terminate(void)
Terminates the connection; finishes any request being currently processed.
void Reset(void)
Resets the parser to the initial state, so that a new request can be parsed.
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.
virtual void OnLinkCreated(cTCPLinkPtr a_Link) override
The link instance has been created, remember it.
cHTTPServer & m_HTTPServer
The HTTP server instance that we're attached to.
virtual ~cHTTPServerConnection() override
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg) override
An error has occurred on the socket.
virtual void SendData(const void *a_Data, size_t a_Size)
Called to send raw data over the link.
virtual void OnHeadersFinished(void) override
Called when all the headers have been parsed.
void SendStatusAndReason(int a_StatusCode, const AString &a_Reason)
Sends HTTP status code together with a_Reason (used for HTTP errors).
cTCPLinkPtr m_Link
The network link attached to this connection.
cHTTPServer & m_HTTPServer
The parent webserver that is to be notified of events on this connection.
std::shared_ptr< cTCPLink > cTCPLinkPtr
AString & Printf(AString &str, const char *format, fmt::ArgList args)
Output the formatted text into the string.
void SendNeedAuth(const AString &a_Realm)
Sends the "401 unauthorized" reply together with instructions on authorizing, using the specified rea...
virtual void OnRemoteClosed(void) override
The socket has been closed for any reason.
void FinishResponse(void)
Indicates that the current response is finished, gets ready for receiving another request (HTTP 1...
std::unique_ptr< cHTTPIncomingRequest > m_CurrentRequest
The request being currently received Valid only between having parsed the headers and finishing recei...
virtual void OnReceivedData(const char *a_Data, size_t a_Size) override
Data is received from the client.
virtual void OnFirstLine(const AString &a_FirstLine) override
Called when the first line of the request or response is fully parsed.
void Send(const cHTTPOutgoingResponse &a_Response)
Sends the headers contained in a_Response.
AStringVector StringSplit(const AString &str, const AString &delim)
Split the string at any of the listed delimiters.
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...
size_t Parse(const char *a_Data, size_t a_Size)
Parses the incoming data and calls the appropriate callbacks.