CppServer 1.0.5.0
C++ Server Library
Loading...
Searching...
No Matches
https_session.h
Go to the documentation of this file.
1
9#ifndef CPPSERVER_HTTP_HTTPS_SESSION_H
10#define CPPSERVER_HTTP_HTTPS_SESSION_H
11
12#include "http_request.h"
13#include "http_response.h"
14
15#include "cache/filecache.h"
17
18namespace CppServer {
19namespace HTTP {
20
21class HTTPSServer;
22
24
30{
31public:
32 explicit HTTPSSession(const std::shared_ptr<HTTPSServer>& server);
33 HTTPSSession(const HTTPSSession&) = delete;
35 virtual ~HTTPSSession() = default;
36
39
41 CppCommon::FileCache& cache() noexcept { return _cache; }
42 const CppCommon::FileCache& cache() const noexcept { return _cache; }
43
45 HTTPResponse& response() noexcept { return _response; }
46 const HTTPResponse& response() const noexcept { return _response; }
47
49
52 size_t SendResponse() { return SendResponse(_response); }
54
58 size_t SendResponse(const HTTPResponse& response) { return Send(response.cache()); }
59
61
65 size_t SendResponseBody(std::string_view body) { return Send(body); }
67
72 size_t SendResponseBody(const void* buffer, size_t size) { return Send(buffer, size); }
73
75
79 size_t SendResponse(const CppCommon::Timespan& timeout) { return SendResponse(_response, timeout); }
81
86 size_t SendResponse(const HTTPResponse& response, const CppCommon::Timespan& timeout) { return Send(response.cache(), timeout); }
87
89
94 size_t SendResponseBody(std::string_view body, const CppCommon::Timespan& timeout) { return Send(body, timeout); }
96
102 size_t SendResponseBody(const void* buffer, size_t size, const CppCommon::Timespan& timeout) { return Send(buffer, size, timeout); }
103
105
110
115
117
121 bool SendResponseBodyAsync(std::string_view body) { return SendAsync(body); }
123
128 bool SendResponseBodyAsync(const void* buffer, size_t size) { return SendAsync(buffer, size); }
129
130protected:
131 void onReceived(const void* buffer, size_t size) override;
132 void onDisconnected() override;
133
135
141 virtual void onReceivedRequestHeader(const HTTPRequest& request) {}
142
144
150 virtual void onReceivedRequest(const HTTPRequest& request) {}
152
163 virtual void onReceivedCachedRequest(const HTTPRequest& request, std::string_view content) { SendAsync(content); }
164
166
173 virtual void onReceivedRequestError(const HTTPRequest& request, const std::string& error) {}
174
175protected:
180
181private:
182 // Static content cache
183 CppCommon::FileCache& _cache;
184
185 void onReceivedRequestInternal(const HTTPRequest& request);
186};
187
188} // namespace HTTP
189} // namespace CppServer
190
191#endif // CPPSERVER_HTTP_HTTPS_SESSION_H
virtual bool SendAsync(const void *buffer, size_t size)
Send data to the client (asynchronous)
std::shared_ptr< SSLServer > & server() noexcept
Get the server.
Definition ssl_session.h:48
virtual size_t Send(const void *buffer, size_t size)
Send data to the client (synchronous)
const std::string & cache() const noexcept
Get the HTTP response cache content.
virtual ~HTTPSSession()=default
bool SendResponseAsync(const HTTPResponse &response)
Send the HTTP response (asynchronous)
void onDisconnected() override
Handle session disconnected notification.
size_t SendResponse()
Send the current HTTP response (synchronous)
HTTPSSession(HTTPSSession &&)=delete
CppCommon::FileCache & cache() noexcept
Get the static content cache.
virtual void onReceivedRequestHeader(const HTTPRequest &request)
Handle HTTP request header received notification.
size_t SendResponseBody(std::string_view body)
Send the HTTP response body (synchronous)
HTTPSSession(const HTTPSSession &)=delete
bool SendResponseBodyAsync(std::string_view body)
Send the HTTP response body (asynchronous)
size_t SendResponse(const CppCommon::Timespan &timeout)
Send the current HTTP response with timeout (synchronous)
HTTPRequest _request
HTTP request.
size_t SendResponse(const HTTPResponse &response)
Send the HTTP response (synchronous)
size_t SendResponseBody(const void *buffer, size_t size)
Send the HTTP response body (synchronous)
size_t SendResponseBody(const void *buffer, size_t size, const CppCommon::Timespan &timeout)
Send the HTTP response body with timeout (synchronous)
const CppCommon::FileCache & cache() const noexcept
virtual void onReceivedRequestError(const HTTPRequest &request, const std::string &error)
Handle HTTP request error notification.
virtual void onReceivedRequest(const HTTPRequest &request)
Handle HTTP request received notification.
void onReceived(const void *buffer, size_t size) override
Handle buffer received notification.
HTTPResponse _response
HTTP response.
bool SendResponseAsync()
Send the current HTTP response (asynchronous)
bool SendResponseBodyAsync(const void *buffer, size_t size)
Send the HTTP response body (asynchronous)
HTTPResponse & response() noexcept
Get the HTTP response.
HTTPSSession & operator=(const HTTPSSession &)=delete
HTTPSSession & operator=(HTTPSSession &&)=delete
size_t SendResponseBody(std::string_view body, const CppCommon::Timespan &timeout)
Send the HTTP response body with timeout (synchronous)
size_t SendResponse(const HTTPResponse &response, const CppCommon::Timespan &timeout)
Send the HTTP response with timeout (synchronous)
virtual void onReceivedCachedRequest(const HTTPRequest &request, std::string_view content)
Handle HTTP cached request received notification.
const HTTPResponse & response() const noexcept
HTTP request definition.
HTTP response definition.
C++ Server project definitions.
Definition asio.h:56
SSL session definition.