$darkmode
Kourier 1.0.0
|
The HttpRequest class represents an HTTP request. More...
Public Types | |
enum class | BodyType { NoBody = 0 , NotChunked , Chunked } |
This enum describes the request's body type. More... | |
enum class | Method { GET = 0 , PUT , POST , PATCH , DELETE , HEAD , OPTIONS } |
This enum describes the HTTP request method. More... | |
Public Member Functions | |
~HttpRequest () | |
std::string_view | body () const |
BodyType | bodyType () const |
bool | chunked () const |
bool | hasBody () const |
bool | hasHeader (std::string_view name) const |
std::string_view | header (std::string_view name, int pos=1) const |
size_t | headerCount (std::string_view name) const |
size_t | headersCount () const |
bool | isComplete () const |
Method | method () const |
std::string_view | peerAddress () const |
uint16_t | peerPort () const |
size_t | pendingBodySize () const |
size_t | requestBodySize () const |
std::string_view | targetPath () const |
std::string_view | targetQuery () const |
The HttpRequest class represents an HTTP request.
HttpRequest cannot be created by you. It is created by HttpServer and passed as an argument to the mapped handler. You can call HttpServer::addRoute to map handlers to HTTP methods and paths.
HttpServer calls the mapped handler right after it parses the request header block. If the request has a body that is not chunked, HttpServer processes all body data that were available when the header block was fully parsed. You can call isComplete() to know if HttpRequest represents a complete request.
HttpRequest is only valid inside the called handler. You cannot call its methods outside of the handler function. You can use the HttpBroker instance HttpServer passes as an argument to the handler to receive the pending body data.
|
strong |
This enum describes the request's body type.
|
strong |
Kourier::HttpRequest::~HttpRequest | ( | ) |
Destroys the object.
std::string_view Kourier::HttpRequest::body | ( | ) | const |
This method returns an empty string view if the request has no body or if it has a chunked body. Otherwise, this method returns the available body data when HttpServer parses the headers block. In this case, you can call requestBodySize() to know the size of the request body and pendingBodySize() to know how much body data is still pending to be processed. Both requestBodySize() and pendingBodySize() methods return zero if the body is chunked.
HttpRequest::BodyType Kourier::HttpRequest::bodyType | ( | ) | const |
Returns the request body type.
bool Kourier::HttpRequest::chunked | ( | ) | const |
Returns true if the request has a body given in chunks. If the request has no body or if the body is not given in chunks, this method returns false.
bool Kourier::HttpRequest::hasBody | ( | ) | const |
Returns true if the request has a body. You can call chunked() or bodyType() to know whether the request body is chunked. If the request body is not chunked, you can call requestBodySize() to get the size of the body and body() to fetch the body data that was available at the time HttpServer finished parsing the header block and created this instance before passing it to the mapped handler.
bool Kourier::HttpRequest::hasHeader | ( | std::string_view | name | ) | const |
Returns true if the header block contains at least one field line with the given name.
std::string_view Kourier::HttpRequest::header | ( | std::string_view | name, |
int | pos = 1 |
||
) | const |
Returns the field line's field value with the given name at position pos in the header block. Position is relative to field lines having the same name.
size_t Kourier::HttpRequest::headerCount | ( | std::string_view | name | ) | const |
Returns the number of field lines with the given name in the header block.
size_t Kourier::HttpRequest::headersCount | ( | ) | const |
Returns the number of field lines in the header block.
bool Kourier::HttpRequest::isComplete | ( | ) | const |
Returns true if the request represented by this instance is complete. A request can only be complete when HttpServer calls the mapped handler if the request doesn't have a body or if the body is not chunked and all of its data is available when the request header block is parsed.
HttpRequest::Method Kourier::HttpRequest::method | ( | ) | const |
Returns the request method.
std::string_view Kourier::HttpRequest::peerAddress | ( | ) | const |
Returns the requester's IP.
uint16_t Kourier::HttpRequest::peerPort | ( | ) | const |
Returns the requester's port.
size_t Kourier::HttpRequest::pendingBodySize | ( | ) | const |
Returns the number of bytes pending for the request body to be fully received. If the request has no body or if it has a chunked body, this method returns 0.
size_t Kourier::HttpRequest::requestBodySize | ( | ) | const |
Returns the size of the body in the request. If the request has no body or if it has a chunked body, this method returns 0.
std::string_view Kourier::HttpRequest::targetPath | ( | ) | const |
Returns the request path.
std::string_view Kourier::HttpRequest::targetQuery | ( | ) | const |
Returns the request query. Returns an empty string view if the request has no query.