WebFramework v3.0.12
Web framework for C++.
|
Parsing HTTP request. More...
#include <HTTPRequest.h>
Public Member Functions | |
HTTPRequest (SessionsManager &session, const web::BaseTCPServer &serverReference, interfaces::IStaticFile &staticResources, interfaces::IDynamicFile &dynamicResources, sqlite::SQLiteManager &database, sockaddr clientAddr, streams::IOSocketStream &stream) | |
HTTPRequest (HTTPRequest &&) noexcept=default | |
HTTPRequest (const HTTPRequest &)=default | |
HTTPRequest & | operator= (HTTPRequest &&) noexcept=default |
HTTPRequest & | operator= (const HTTPRequest &)=default |
const std::string & | getRawParameters () const |
Parameters string from HTTP. | |
const std::string & | getMethod () const |
HTTP request method. | |
const std::unordered_map< std::string, std::string > & | getKeyValueParameters () const |
GET parameters. | |
std::string | getHTTPVersion () const |
HTTP version. | |
const web::HeadersMap & | getHeaders () const |
All HTTP headers. | |
const std::string & | getBody () const |
HTTP request body. | |
void | setAttribute (const std::string &name, const std::string &value) |
Session wrapper. | |
std::string | getAttribute (const std::string &name) |
Session wrapper. | |
void | deleteSession () |
Session wrapper. | |
void | deleteAttribute (const std::string &name) |
Session wrapper. | |
web::HeadersMap | getCookies () const |
Client's cookies. | |
void | sendAssetFile (const std::string &filePath, HTTPResponse &response, const std::unordered_map< std::string, std::string > &variables={}, bool isBinary=true, const std::string &fileName="") |
ResourceExecutor wrapper. | |
void | sendStaticFile (const std::string &filePath, HTTPResponse &response, bool isBinary=true, const std::string &fileName="") |
void | sendDynamicFile (const std::string &filePath, HTTPResponse &response, const std::unordered_map< std::string, std::string > &variables, bool isBinary=false, const std::string &fileName="") |
void | streamFile (std::string_view filePath, HTTPResponse &response, std::string_view fileName, size_t chunkSize=defaultChunkSize) |
void | registerDynamicFunction (const std::string &functionName, std::function< std::string(const std::vector< std::string > &)> &&function) |
Add new function in .wfdp interpreter. | |
void | unregisterDynamicFunction (const std::string &functionName) |
Remove function from .wfdp interpreter. | |
bool | isDynamicFunctionRegistered (const std::string &functionName) |
Check if function is registered. | |
const json::JSONParser & | getJSON () const |
Getter for JSONParser. | |
const std::vector< std::string > & | getChunks () const |
Get chunks. | |
const web::HTTPParser & | getParser () const |
HTTP parser getter. | |
std::string | getClientIpV4 () const |
Get client's address. | |
std::string | getServerIpV4 () const |
Get server's address. | |
uint16_t | getClientPort () const |
Get client's port. | |
uint16_t | getServerPort () const |
Get server's port. | |
template<utility::concepts::RouteParameterType T> | |
const T & | getRouteParameter (const std::string &routeParameterName) |
Getter for route parameters. | |
template<std::derived_from< sqlite::SQLiteDatabaseModel > T, typename... Args> | |
std::shared_ptr< T > | createModel (Args &&... args) |
First call creates model with arguments other calls returns created model. | |
template<std::derived_from< sqlite::SQLiteDatabaseModel > T> | |
std::shared_ptr< T > | getModel () const |
First call creates model without arguments other calls returns created model. | |
template<std::derived_from< utility::ChunkGenerator > T, typename... Args> | |
void | sendChunks (HTTPResponse &response, Args &&... args) |
Send runtime generated content. | |
template<std::derived_from< utility::ChunkGenerator > T, typename... Args> | |
void | sendFileChunks (HTTPResponse &response, std::string_view fileName, Args &&... args) |
Send file. | |
template<> | |
WEB_FRAMEWORK_API const string & | getRouteParameter (const string &routeParameterName) |
template<> | |
WEB_FRAMEWORK_API const int64_t & | getRouteParameter (const string &routeParameterName) |
template<> | |
WEB_FRAMEWORK_API const double & | getRouteParameter (const string &routeParameterName) |
Static Public Member Functions | |
static web::HTTPParser | sendRequestToAnotherServer (std::string_view ip, std::string_view port, std::string_view request, DWORD timeout=30 '000, bool useHTTPS=false) |
Friends | |
class | ExecutorsManager |
streams::IOSocketStream & | operator>> (streams::IOSocketStream &stream, HTTPRequest &request) |
Reading HTTP request from network. | |
std::ostream & | operator<< (std::ostream &stream, const HTTPRequest &request) |
Logging operator. | |
Parsing HTTP request.
Accessing to sessions
Overriding input stream operator for simplify HTTP request initializing
Definition at line 24 of file HTTPRequest.h.
framework::HTTPRequest::HTTPRequest | ( | SessionsManager & | session, |
const web::BaseTCPServer & | serverReference, | ||
interfaces::IStaticFile & | staticResources, | ||
interfaces::IDynamicFile & | dynamicResources, | ||
sqlite::SQLiteManager & | database, | ||
sockaddr | clientAddr, | ||
streams::IOSocketStream & | stream ) |
Definition at line 40 of file HTTPRequest.cpp.
std::shared_ptr< T > framework::HTTPRequest::createModel | ( | Args &&... | args | ) |
First call creates model with arguments other calls returns created model.
...Args | |
T |
...args |
Definition at line 284 of file HTTPRequest.h.
void framework::HTTPRequest::deleteAttribute | ( | const std::string & | name | ) |
void framework::HTTPRequest::deleteSession | ( | ) |
Session wrapper.
Definition at line 92 of file HTTPRequest.cpp.
string framework::HTTPRequest::getAttribute | ( | const std::string & | name | ) |
Session wrapper.
name | attribute name |
std::out_of_range |
Definition at line 87 of file HTTPRequest.cpp.
const string & framework::HTTPRequest::getBody | ( | ) | const |
const vector< string > & framework::HTTPRequest::getChunks | ( | ) | const |
string framework::HTTPRequest::getClientIpV4 | ( | ) | const |
uint16_t framework::HTTPRequest::getClientPort | ( | ) | const |
web::HeadersMap framework::HTTPRequest::getCookies | ( | ) | const |
const web::HeadersMap & framework::HTTPRequest::getHeaders | ( | ) | const |
string framework::HTTPRequest::getHTTPVersion | ( | ) | const |
const json::JSONParser & framework::HTTPRequest::getJSON | ( | ) | const |
const unordered_map< string, string > & framework::HTTPRequest::getKeyValueParameters | ( | ) | const |
const string & framework::HTTPRequest::getMethod | ( | ) | const |
std::shared_ptr< T > framework::HTTPRequest::getModel | ( | ) | const |
First call creates model without arguments other calls returns created model.
T |
Definition at line 290 of file HTTPRequest.h.
const web::HTTPParser & framework::HTTPRequest::getParser | ( | ) | const |
const string & framework::HTTPRequest::getRawParameters | ( | ) | const |
const T & framework::HTTPRequest::getRouteParameter | ( | const std::string & | routeParameterName | ) |
Getter for route parameters.
T | RouteParameterType type |
routeParameterName | Name of route parameter |
std::out_of_range | Can't find route parameter with this routeParameterName |
WEB_FRAMEWORK_API const string & framework::HTTPRequest::getRouteParameter | ( | const string & | routeParameterName | ) |
Definition at line 278 of file HTTPRequest.cpp.
WEB_FRAMEWORK_API const int64_t & framework::HTTPRequest::getRouteParameter | ( | const string & | routeParameterName | ) |
Definition at line 284 of file HTTPRequest.cpp.
WEB_FRAMEWORK_API const double & framework::HTTPRequest::getRouteParameter | ( | const string & | routeParameterName | ) |
Definition at line 290 of file HTTPRequest.cpp.
string framework::HTTPRequest::getServerIpV4 | ( | ) | const |
uint16_t framework::HTTPRequest::getServerPort | ( | ) | const |
bool framework::HTTPRequest::isDynamicFunctionRegistered | ( | const std::string & | functionName | ) |
Check if function is registered.
functionName | Name of function |
Definition at line 237 of file HTTPRequest.cpp.
void framework::HTTPRequest::registerDynamicFunction | ( | const std::string & | functionName, |
std::function< std::string(const std::vector< std::string > &)> && | function ) |
Add new function in .wfdp interpreter.
functionName | Name of new function |
function | Function implementation |
Definition at line 227 of file HTTPRequest.cpp.
void framework::HTTPRequest::sendAssetFile | ( | const std::string & | filePath, |
HTTPResponse & | response, | ||
const std::unordered_map< std::string, std::string > & | variables = {}, | ||
bool | isBinary = true, | ||
const std::string & | fileName = "" ) |
ResourceExecutor wrapper.
filePath | path to asset file from assets folder |
fileName | Optional parameter for specifying name of file in Content-Disposition HTTP header, ASCII name required |
framework::exceptions::DynamicPagesSyntaxException | |
std::exception |
Definition at line 135 of file HTTPRequest.cpp.
void framework::HTTPRequest::sendChunks | ( | HTTPResponse & | response, |
Args &&... | args ) |
Send runtime generated content.
...Args | |
T |
response | |
...args |
Definition at line 313 of file HTTPRequest.h.
void framework::HTTPRequest::sendDynamicFile | ( | const std::string & | filePath, |
HTTPResponse & | response, | ||
const std::unordered_map< std::string, std::string > & | variables, | ||
bool | isBinary = false, | ||
const std::string & | fileName = "" ) |
Send dynamic file(.wfdp)
filePath | Path to asset file from assets folder |
fileName | Optional parameter for specifying name of file in Content-Disposition HTTP header, ASCII name required |
framework::exceptions::DynamicPagesSyntaxException | |
std::exception |
Definition at line 147 of file HTTPRequest.cpp.
void framework::HTTPRequest::sendFileChunks | ( | HTTPResponse & | response, |
std::string_view | fileName, | ||
Args &&... | args ) |
Send file.
...Args | |
T |
response | |
fileName | |
...args |
Definition at line 319 of file HTTPRequest.h.
|
static |
Definition at line 24 of file HTTPRequest.cpp.
void framework::HTTPRequest::sendStaticFile | ( | const std::string & | filePath, |
HTTPResponse & | response, | ||
bool | isBinary = true, | ||
const std::string & | fileName = "" ) |
Send non dynamic file
filePath | Path to asset file from assets folder |
fileName | Optional parameter for specifying name of file in Content-Disposition HTTP header, ASCII name required |
std::exception |
Definition at line 142 of file HTTPRequest.cpp.
void framework::HTTPRequest::setAttribute | ( | const std::string & | name, |
const std::string & | value ) |
Session wrapper.
name | attribute name |
value | attribute value |
Definition at line 82 of file HTTPRequest.cpp.
void framework::HTTPRequest::streamFile | ( | std::string_view | filePath, |
HTTPResponse & | response, | ||
std::string_view | fileName, | ||
size_t | chunkSize = defaultChunkSize ) |
Send large files
filePath | Path to asset file from assets folder |
fileName | Name of file in Content-Disposition HTTP header, ASCII name required |
chunkSize | Desired size of read data before sending |
Definition at line 152 of file HTTPRequest.cpp.
void framework::HTTPRequest::unregisterDynamicFunction | ( | const std::string & | functionName | ) |
Remove function from .wfdp interpreter.
functionName | Name of function |
Definition at line 232 of file HTTPRequest.cpp.
|
friend |
Definition at line 278 of file HTTPRequest.h.
|
friend |
Logging operator.
stream | any output source |
request | class instance |
|
friend |
Reading HTTP request from network.
stream | special class for taking data from network |
request | class instance |
web::WebException |
Definition at line 295 of file HTTPRequest.cpp.