userver: server::http::HttpRequest Class Reference
Loading...
Searching...
No Matches
server::http::HttpRequest Class Referencefinal

#include <userver/server/http/http_request.hpp>

Detailed Description

Public Types

using HeadersMap = ::http::headers::HeaderMap
 
using HeadersMapKeys = decltype(utils::impl::MakeKeysView(HeadersMap()))
 
using CookiesMap = std::unordered_map<std::string, std::string, utils::StrCaseHash>
 
using CookiesMapKeys = decltype(utils::impl::MakeKeysView(CookiesMap()))
 

Public Member Functions

HttpResponseGetHttpResponse () const
 Returns a container that should be filled with response data to this request.
 
const HttpMethodGetMethod () const
 
const std::string & GetMethodStr () const
 
int GetHttpMajor () const
 
int GetHttpMinor () const
 
const std::string & GetUrl () const
 
const std::string & GetRequestPath () const
 
const std::string & GetPathSuffix () const
 
std::chrono::duration< double > GetRequestTime () const
 
std::chrono::duration< double > GetResponseTime () const
 
const std::string & GetHost () const
 
const engine::io::SockaddrGetRemoteAddress () const
 
const std::string & GetArg (std::string_view arg_name) const
 
const std::vector< std::string > & GetArgVector (std::string_view arg_name) const
 
bool HasArg (std::string_view arg_name) const
 
size_t ArgCount () const
 
std::vector< std::string > ArgNames () const
 
const FormDataArgGetFormDataArg (std::string_view arg_name) const
 
const std::vector< FormDataArg > & GetFormDataArgVector (std::string_view arg_name) const
 
bool HasFormDataArg (std::string_view arg_name) const
 
size_t FormDataArgCount () const
 
std::vector< std::string > FormDataArgNames () const
 
const std::string & GetPathArg (std::string_view arg_name) const
 
const std::string & GetPathArg (size_t index) const
 
bool HasPathArg (std::string_view arg_name) const
 
bool HasPathArg (size_t index) const
 
size_t PathArgCount () const
 
const std::string & GetHeader (std::string_view header_name) const
 
const std::string & GetHeader (const ::http::headers::PredefinedHeader &header_name) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const HeadersMapGetHeaders () const
 
bool HasHeader (std::string_view header_name) const
 
bool HasHeader (const ::http::headers::PredefinedHeader &header_name) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
size_t HeaderCount () const
 
HeadersMapKeys GetHeaderNames () const
 
void RemoveHeader (std::string_view header_name)
 Removes the header with case insensitive name header_name.
 
void RemoveHeader (const ::http::headers::PredefinedHeader &header_name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const std::string & GetCookie (const std::string &cookie_name) const
 
bool HasCookie (const std::string &cookie_name) const
 
size_t CookieCount () const
 
CookiesMapKeys GetCookieNames () const
 
const std::string & RequestBody () const
 
const HeadersMapRequestHeaders () const
 
const CookiesMap & RequestCookies () const
 
void SetResponseStatus (HttpStatus status) const
 Set the response status code.
 
bool IsBodyCompressed () const
 

Member Typedef Documentation

◆ CookiesMap

using server::http::HttpRequest::CookiesMap = std::unordered_map<std::string, std::string, utils::StrCaseHash>

Definition at line 44 of file http_request.hpp.

◆ CookiesMapKeys

using server::http::HttpRequest::CookiesMapKeys = decltype(utils::impl::MakeKeysView(CookiesMap()))

Definition at line 46 of file http_request.hpp.

◆ HeadersMap

◆ HeadersMapKeys

using server::http::HttpRequest::HeadersMapKeys = decltype(utils::impl::MakeKeysView(HeadersMap()))

Definition at line 42 of file http_request.hpp.

Member Function Documentation

◆ ArgCount()

size_t server::http::HttpRequest::ArgCount ( ) const
Returns
Count of arguments. Arguments are extracted from:
  • query part of the URL,
  • the HTTP body (only if parse_args_from_body: true for handler is set).

◆ ArgNames()

std::vector< std::string > server::http::HttpRequest::ArgNames ( ) const
Returns
List of names of arguments. Arguments are extracted from:
  • query part of the URL,
  • the HTTP body (only if parse_args_from_body: true for handler is set).

◆ CookieCount()

size_t server::http::HttpRequest::CookieCount ( ) const
Returns
Number of cookies.

◆ FormDataArgCount()

size_t server::http::HttpRequest::FormDataArgCount ( ) const
Returns
Count of multipart/form-data arguments.

◆ FormDataArgNames()

std::vector< std::string > server::http::HttpRequest::FormDataArgNames ( ) const
Returns
List of names of multipart/form-data arguments.

◆ GetArg()

const std::string & server::http::HttpRequest::GetArg ( std::string_view arg_name) const
Returns
First argument value with name arg_name or an empty string if no such argument. Arguments are extracted from:
  • query part of the URL,
  • the HTTP body (only if parse_args_from_body: true for handler is set).

In both cases, arg keys and values are url-decoded automatically when parsing into the HttpRequest.

Examples
postgresql/functional_tests/basic_chaos/postgres_service.cpp, samples/hello_service/src/hello_handler.cpp, samples/http_caching/http_caching.cpp, samples/mongo_service/mongo_service.cpp, samples/postgres_service/postgres_service.cpp, and samples/redis_service/redis_service.cpp.

◆ GetArgVector()

const std::vector< std::string > & server::http::HttpRequest::GetArgVector ( std::string_view arg_name) const
Returns
Argument values with name arg_name or an empty vector if no such argument. Arguments are extracted from:
  • query part of the URL,
  • the HTTP body (only if parse_args_from_body: true for handler is set).

In both cases, arg keys and values are url-decoded automatically when parsing into the HttpRequest.

◆ GetCookie()

const std::string & server::http::HttpRequest::GetCookie ( const std::string & cookie_name) const
Returns
Value of the cookie with case sensitive name cookie_name, or an empty string if no such cookie exists.

◆ GetCookieNames()

CookiesMapKeys server::http::HttpRequest::GetCookieNames ( ) const
Returns
List of cookies names.

◆ GetFormDataArg()

const FormDataArg & server::http::HttpRequest::GetFormDataArg ( std::string_view arg_name) const
Returns
First argument value with name arg_name from multipart/form-data request or an empty FormDataArg if no such argument.
Examples
samples/multipart_service/service.cpp.

◆ GetFormDataArgVector()

const std::vector< FormDataArg > & server::http::HttpRequest::GetFormDataArgVector ( std::string_view arg_name) const
Returns
Argument values with name arg_name from multipart/form-data request or an empty FormDataArg if no such argument.

◆ GetHeader()

const std::string & server::http::HttpRequest::GetHeader ( std::string_view header_name) const
Returns
Value of the header with case insensitive name header_name, or an empty string if no such header.
Examples
samples/multipart_service/service.cpp, and samples/postgres_auth/auth_bearer.cpp.

◆ GetHeaderNames()

HeadersMapKeys server::http::HttpRequest::GetHeaderNames ( ) const
Returns
List of headers names.

◆ GetHost()

const std::string & server::http::HttpRequest::GetHost ( ) const
Returns
Host from the URL.

◆ GetHttpMajor()

int server::http::HttpRequest::GetHttpMajor ( ) const
Returns
Major version of HTTP. For example, for HTTP 1.0 it returns 1

◆ GetHttpMinor()

int server::http::HttpRequest::GetHttpMinor ( ) const
Returns
Minor version of HTTP. For example, for HTTP 1.0 it returns 0

◆ GetPathArg() [1/2]

const std::string & server::http::HttpRequest::GetPathArg ( size_t index) const
Returns
Argument from URL path with wildcards by its 0-based index.
Note
Path args are currently NOT url-decoded automatically.

◆ GetPathArg() [2/2]

const std::string & server::http::HttpRequest::GetPathArg ( std::string_view arg_name) const
Returns
Named argument from URL path with wildcards.
Note
Path args are currently NOT url-decoded automatically.

◆ GetPathSuffix()

const std::string & server::http::HttpRequest::GetPathSuffix ( ) const
Returns
Request path suffix, i.e. part of the path that remains after matching the path of a handler.

◆ GetRemoteAddress()

const engine::io::Sockaddr & server::http::HttpRequest::GetRemoteAddress ( ) const
Returns
Request remote address

◆ GetRequestPath()

const std::string & server::http::HttpRequest::GetRequestPath ( ) const
Returns
Request path

◆ GetUrl()

const std::string & server::http::HttpRequest::GetUrl ( ) const
Returns
Request URL

◆ HasArg()

bool server::http::HttpRequest::HasArg ( std::string_view arg_name) const
Returns
true if argument with name arg_name exists, false otherwise. Arguments are extracted from:
  • query part of the URL,
  • the HTTP body (only if parse_args_from_body: true for handler is set).

In both cases, arg keys and values are url-decoded automatically when parsing into the HttpRequest.

Examples
samples/mongo_service/mongo_service.cpp.

◆ HasCookie()

bool server::http::HttpRequest::HasCookie ( const std::string & cookie_name) const
Returns
true if cookie with case sensitive name cookie_name exists, false otherwise.

◆ HasFormDataArg()

bool server::http::HttpRequest::HasFormDataArg ( std::string_view arg_name) const
Returns
true if argument with name arg_name exists in multipart/form-data request, false otherwise.

◆ HasHeader()

bool server::http::HttpRequest::HasHeader ( std::string_view header_name) const
Returns
true if header with case insensitive name header_name exists, false otherwise.

◆ HasPathArg() [1/2]

bool server::http::HttpRequest::HasPathArg ( size_t index) const
Returns
true if argument with index from URL path with wildcards exists, false otherwise.

◆ HasPathArg() [2/2]

bool server::http::HttpRequest::HasPathArg ( std::string_view arg_name) const
Returns
true if named argument from URL path with wildcards exists, false otherwise.

◆ HeaderCount()

size_t server::http::HttpRequest::HeaderCount ( ) const
Returns
Number of headers.

◆ IsBodyCompressed()

bool server::http::HttpRequest::IsBodyCompressed ( ) const
Returns
true if the body of the request is still compressed. In other words returns true if the static option decompress_request of a handler was set to false and this is a compressed request.

◆ PathArgCount()

size_t server::http::HttpRequest::PathArgCount ( ) const
Returns
Number of wildcard arguments in URL path.

◆ RequestBody()

const std::string & server::http::HttpRequest::RequestBody ( ) const
Returns
HTTP body.

◆ RequestCookies()

const CookiesMap & server::http::HttpRequest::RequestCookies ( ) const
Returns
HTTP cookies.

◆ RequestHeaders()

const HeadersMap & server::http::HttpRequest::RequestHeaders ( ) const
Returns
HTTP headers.

◆ SetResponseStatus()

void server::http::HttpRequest::SetResponseStatus ( HttpStatus status) const

Friends And Related Symbol Documentation

◆ handlers::HttpHandlerBase

friend class handlers::HttpHandlerBase
friend

Definition at line 236 of file http_request.hpp.


The documentation for this class was generated from the following file: