Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
cHTTPServerConnection Class Reference

#include <HTTPServerConnection.h>

Inheritance diagram for cHTTPServerConnection:
Inheritance graph
[legend]
Collaboration diagram for cHTTPServerConnection:
Collaboration graph
[legend]

Public Member Functions

 cHTTPServerConnection (cHTTPServer &a_HTTPServer)
 Creates a new instance, connected to the specified HTTP server instance. More...
 
void FinishResponse (void)
 Indicates that the current response is finished, gets ready for receiving another request (HTTP 1.1 keepalive). More...
 
void Send (const AString &a_Data)
 Sends the data as the response (may be called multiple times) More...
 
void Send (const cHTTPOutgoingResponse &a_Response)
 Sends the headers contained in a_Response. More...
 
void Send (const void *a_Data, size_t a_Size)
 Sends the data as the response (may be called multiple times) More...
 
void SendNeedAuth (const AString &a_Realm)
 Sends the "401 unauthorized" reply together with instructions on authorizing, using the specified realm. More...
 
void SendStatusAndReason (int a_StatusCode, const AString &a_Reason)
 Sends HTTP status code together with a_Reason (used for HTTP errors). More...
 
void Terminate (void)
 Terminates the connection; finishes any request being currently processed. More...
 
virtual ~cHTTPServerConnection () override
 
- Public Member Functions inherited from cTCPLink::cCallbacks
virtual void OnTlsHandshakeCompleted (void)
 Called when the TLS handshake has been completed and communication can continue regularly. More...
 
virtual ~cCallbacks ()
 
- Public Member Functions inherited from cHTTPMessageParser::cCallbacks
virtual ~cCallbacks ()
 

Protected Types

typedef std::map< AString, AStringcNameValueMap
 

Protected Member Functions

virtual void OnBodyData (const void *a_Data, size_t a_Size) override
 Called for each chunk of the incoming body data. More...
 
virtual void OnBodyFinished (void) override
 Called when the entire body has been reported by OnBodyData(). More...
 
virtual void OnError (const AString &a_ErrorDescription) override
 Called when an error has occured while parsing. More...
 
virtual void OnError (int a_ErrorCode, const AString &a_ErrorMsg) override
 An error has occurred on the socket. More...
 
virtual void OnFirstLine (const AString &a_FirstLine) override
 Called when the first line of the request or response is fully parsed. More...
 
virtual void OnHeaderLine (const AString &a_Key, const AString &a_Value) override
 Called when a single header line is parsed. More...
 
virtual void OnHeadersFinished (void) override
 Called when all the headers have been parsed. More...
 
virtual void OnLinkCreated (cTCPLinkPtr a_Link) override
 The link instance has been created, remember it. More...
 
virtual void OnReceivedData (const char *a_Data, size_t a_Size) override
 Data is received from the client. More...
 
virtual void OnRemoteClosed (void) override
 The socket has been closed for any reason. More...
 
void SendData (const AString &a_Data)
 Sends the raw data over the link. More...
 
virtual void SendData (const void *a_Data, size_t a_Size)
 Called to send raw data over the link. More...
 

Protected Attributes

std::unique_ptr< cHTTPIncomingRequestm_CurrentRequest
 The request being currently received Valid only between having parsed the headers and finishing receiving the body. More...
 
cHTTPServerm_HTTPServer
 The parent webserver that is to be notified of events on this connection. More...
 
cTCPLinkPtr m_Link
 The network link attached to this connection. More...
 
cHTTPMessageParser m_Parser
 The parser responsible for reading the requests. More...
 

Detailed Description

Definition at line 27 of file HTTPServerConnection.h.

Member Typedef Documentation

◆ cNameValueMap

Definition at line 64 of file HTTPServerConnection.h.

Constructor & Destructor Documentation

◆ cHTTPServerConnection()

cHTTPServerConnection::cHTTPServerConnection ( cHTTPServer a_HTTPServer)

Creates a new instance, connected to the specified HTTP server instance.

Definition at line 15 of file HTTPServerConnection.cpp.

◆ ~cHTTPServerConnection()

cHTTPServerConnection::~cHTTPServerConnection ( )
overridevirtualdefault

Member Function Documentation

◆ FinishResponse()

void cHTTPServerConnection::FinishResponse ( void  )

Indicates that the current response is finished, gets ready for receiving another request (HTTP 1.1 keepalive).

Clears the current request (since it's finished by this call).

Definition at line 80 of file HTTPServerConnection.cpp.

◆ OnBodyData()

void cHTTPServerConnection::OnBodyData ( const void *  a_Data,
size_t  a_Size 
)
overrideprotectedvirtual

Called for each chunk of the incoming body data.

Implements cHTTPMessageParser::cCallbacks.

Definition at line 202 of file HTTPServerConnection.cpp.

◆ OnBodyFinished()

void cHTTPServerConnection::OnBodyFinished ( void  )
overrideprotectedvirtual

Called when the entire body has been reported by OnBodyData().

Implements cHTTPMessageParser::cCallbacks.

Definition at line 215 of file HTTPServerConnection.cpp.

◆ OnError() [1/2]

void cHTTPServerConnection::OnError ( const AString a_ErrorDescription)
overrideprotectedvirtual

Called when an error has occured while parsing.

Implements cHTTPMessageParser::cCallbacks.

Definition at line 149 of file HTTPServerConnection.cpp.

◆ OnError() [2/2]

void cHTTPServerConnection::OnError ( int  a_ErrorCode,
const AString a_ErrorMsg 
)
overrideprotectedvirtual

An error has occurred on the socket.

Implements cTCPLink::cCallbacks.

Definition at line 140 of file HTTPServerConnection.cpp.

◆ OnFirstLine()

void cHTTPServerConnection::OnFirstLine ( const AString a_FirstLine)
overrideprotectedvirtual

Called when the first line of the request or response is fully parsed.

Doesn't check the validity of the line, only extracts the first complete line.

Implements cHTTPMessageParser::cCallbacks.

Definition at line 158 of file HTTPServerConnection.cpp.

◆ OnHeaderLine()

void cHTTPServerConnection::OnHeaderLine ( const AString a_Key,
const AString a_Value 
)
overrideprotectedvirtual

Called when a single header line is parsed.

Implements cHTTPMessageParser::cCallbacks.

Definition at line 176 of file HTTPServerConnection.cpp.

◆ OnHeadersFinished()

void cHTTPServerConnection::OnHeadersFinished ( void  )
overrideprotectedvirtual

Called when all the headers have been parsed.

Implements cHTTPMessageParser::cCallbacks.

Definition at line 189 of file HTTPServerConnection.cpp.

◆ OnLinkCreated()

void cHTTPServerConnection::OnLinkCreated ( cTCPLinkPtr  a_Link)
overrideprotectedvirtual

The link instance has been created, remember it.

Implements cTCPLink::cCallbacks.

Definition at line 106 of file HTTPServerConnection.cpp.

◆ OnReceivedData()

void cHTTPServerConnection::OnReceivedData ( const char *  a_Data,
size_t  a_Size 
)
overrideprotectedvirtual

Data is received from the client.

Implements cTCPLink::cCallbacks.

Reimplemented in cSslHTTPServerConnection.

Definition at line 116 of file HTTPServerConnection.cpp.

◆ OnRemoteClosed()

void cHTTPServerConnection::OnRemoteClosed ( void  )
overrideprotectedvirtual

The socket has been closed for any reason.

Implements cTCPLink::cCallbacks.

Definition at line 127 of file HTTPServerConnection.cpp.

◆ Send() [1/3]

void cHTTPServerConnection::Send ( const AString a_Data)
inline

Sends the data as the response (may be called multiple times)

Definition at line 54 of file HTTPServerConnection.h.

◆ Send() [2/3]

void cHTTPServerConnection::Send ( const cHTTPOutgoingResponse a_Response)

Sends the headers contained in a_Response.

Definition at line 55 of file HTTPServerConnection.cpp.

◆ Send() [3/3]

void cHTTPServerConnection::Send ( const void *  a_Data,
size_t  a_Size 
)

Sends the data as the response (may be called multiple times)

Definition at line 67 of file HTTPServerConnection.cpp.

◆ SendData() [1/2]

void cHTTPServerConnection::SendData ( const AString a_Data)
inlineprotected

Sends the raw data over the link.

Descendants may provide data transformations (SSL etc.) via the overridable SendData() function.

Definition at line 107 of file HTTPServerConnection.h.

◆ SendData() [2/2]

void cHTTPServerConnection::SendData ( const void *  a_Data,
size_t  a_Size 
)
protectedvirtual

Called to send raw data over the link.

Descendants may provide data transformations (SSL etc.)

Reimplemented in cSslHTTPServerConnection.

Definition at line 232 of file HTTPServerConnection.cpp.

◆ SendNeedAuth()

void cHTTPServerConnection::SendNeedAuth ( const AString a_Realm)

Sends the "401 unauthorized" reply together with instructions on authorizing, using the specified realm.

Clears the current request (since it's finished by this call).

Definition at line 44 of file HTTPServerConnection.cpp.

◆ SendStatusAndReason()

void cHTTPServerConnection::SendStatusAndReason ( int  a_StatusCode,
const AString a_Reason 
)

Sends HTTP status code together with a_Reason (used for HTTP errors).

Sends the a_Reason as the body as well, so that browsers display it. Clears the current request (since it's finished by this call).

Definition at line 31 of file HTTPServerConnection.cpp.

◆ Terminate()

void cHTTPServerConnection::Terminate ( void  )

Terminates the connection; finishes any request being currently processed.

Definition at line 92 of file HTTPServerConnection.cpp.

Member Data Documentation

◆ m_CurrentRequest

std::unique_ptr<cHTTPIncomingRequest> cHTTPServerConnection::m_CurrentRequest
protected

The request being currently received Valid only between having parsed the headers and finishing receiving the body.

Definition at line 74 of file HTTPServerConnection.h.

◆ m_HTTPServer

cHTTPServer& cHTTPServerConnection::m_HTTPServer
protected

The parent webserver that is to be notified of events on this connection.

Definition at line 67 of file HTTPServerConnection.h.

◆ m_Link

cTCPLinkPtr cHTTPServerConnection::m_Link
protected

The network link attached to this connection.

Definition at line 77 of file HTTPServerConnection.h.

◆ m_Parser

cHTTPMessageParser cHTTPServerConnection::m_Parser
protected

The parser responsible for reading the requests.

Definition at line 70 of file HTTPServerConnection.h.


The documentation for this class was generated from the following files: