16 : Asio::TCPSession(server),
17 _cache(server->cache())
26 if (
_request.ReceiveHeader(buffer, size))
42 if (
_request.ReceiveBody(buffer, size))
70 void 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)));
virtual bool Disconnect()
Disconnect the session.
HTTPRequest & Clear()
Clear the HTTP request cache.
std::string_view method() const noexcept
Get the HTTP request method.
bool error() const noexcept
Is the HTTP request error flag set?
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)
HTTPResponse & response() noexcept
Get the HTTP response.
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.
C++ Server project definitions.