9 #ifndef CPPSERVER_HTTP_HTTP_SESSION_H
10 #define CPPSERVER_HTTP_HTTP_SESSION_H
15 #include "cache/filecache.h"
41 CppCommon::FileCache&
cache() noexcept {
return _cache; }
42 const CppCommon::FileCache&
cache() const noexcept {
return _cache; }
94 size_t SendResponseBody(std::string_view body,
const CppCommon::Timespan& timeout) {
return Send(body, timeout); }
102 size_t SendResponseBody(
const void* buffer,
size_t size,
const CppCommon::Timespan& timeout) {
return Send(buffer, size, timeout); }
131 void onReceived(
const void* buffer,
size_t size)
override;
183 CppCommon::FileCache& _cache;
185 void onReceivedRequestInternal(
const HTTPRequest& request);
virtual bool SendAsync(const void *buffer, size_t size)
Send data to the client (asynchronous)
virtual size_t Send(const void *buffer, size_t size)
Send data to the client (synchronous)
std::shared_ptr< TCPServer > & server() noexcept
Get the server.
const std::string & cache() const noexcept
Get the HTTP response cache content.
bool SendResponseBodyAsync(const void *buffer, size_t size)
Send the HTTP response body (asynchronous)
HTTPSession & operator=(const HTTPSession &)=delete
HTTPRequest _request
HTTP request.
virtual void onReceivedCachedRequest(const HTTPRequest &request, std::string_view content)
Handle HTTP cached request received notification.
HTTPSession & operator=(HTTPSession &&)=delete
size_t SendResponseBody(std::string_view body)
Send the HTTP response body (synchronous)
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.
size_t SendResponse(const HTTPResponse &response, const CppCommon::Timespan &timeout)
Send the HTTP response with timeout (synchronous)
void onReceived(const void *buffer, size_t size) override
Handle buffer received notification.
size_t SendResponseBody(std::string_view body, const CppCommon::Timespan &timeout)
Send the HTTP response body with timeout (synchronous)
bool SendResponseBodyAsync(std::string_view body)
Send the HTTP response body (asynchronous)
virtual void onReceivedRequestError(const HTTPRequest &request, const std::string &error)
Handle HTTP request error notification.
HTTPSession(const HTTPSession &)=delete
virtual ~HTTPSession()=default
size_t SendResponse(const HTTPResponse &response)
Send the HTTP response (synchronous)
HTTPResponse _response
HTTP response.
size_t SendResponse(const CppCommon::Timespan &timeout)
Send the current HTTP response with timeout (synchronous)
bool SendResponseAsync()
Send the current HTTP response (asynchronous)
CppCommon::FileCache & cache() noexcept
Get the static content cache.
virtual void onReceivedRequest(const HTTPRequest &request)
Handle HTTP request received notification.
size_t SendResponseBody(const void *buffer, size_t size, const CppCommon::Timespan &timeout)
Send the HTTP response body with timeout (synchronous)
size_t SendResponse()
Send the current HTTP response (synchronous)
HTTPSession(HTTPSession &&)=delete
bool SendResponseAsync(const HTTPResponse &response)
Send the HTTP response (asynchronous)
const CppCommon::FileCache & cache() const noexcept
const HTTPResponse & response() const noexcept
size_t SendResponseBody(const void *buffer, size_t size)
Send the HTTP response body (synchronous)
HTTP response definition.
C++ Server project definitions.