26 if (
_request.ReceiveHeader(buffer, size))
42 if (
_request.ReceiveBody(buffer, size))
70void HTTPSession::onReceivedRequestInternal(
const HTTPRequest& request)
73 if (request.
method() ==
"GET")
75 std::string_view url = request.
url();
76 size_t index = url.find(
'?');
77 auto response =
cache().find(std::string((index == std::string_view::npos) ? url : url.substr(0, index)));
TCPSession(const std::shared_ptr< TCPServer > &server)
Initialize the session with a given server.
std::shared_ptr< TCPServer > & server() noexcept
Get the server.
virtual bool Disconnect()
Disconnect the session.
std::string_view method() const noexcept
Get the HTTP request method.
std::string_view url() const noexcept
Get the HTTP request URL.
HTTPRequest _request
HTTP request.
virtual void onReceivedCachedRequest(const HTTPRequest &request, std::string_view content)
Handle HTTP cached request received notification.
virtual void onReceivedRequestHeader(const HTTPRequest &request)
Handle HTTP request header received notification.
HTTPSession(const std::shared_ptr< HTTPServer > &server)
void onDisconnected() override
Handle session disconnected notification.
void onReceived(const void *buffer, size_t size) override
Handle buffer received notification.
virtual void onReceivedRequestError(const HTTPRequest &request, const std::string &error)
Handle HTTP request error notification.
CppCommon::FileCache & cache() noexcept
Get the static content cache.
virtual void onReceivedRequest(const HTTPRequest &request)
Handle HTTP request received notification.
HTTPResponse & response() noexcept
Get the HTTP response.
C++ Server project definitions.