Fawkes API  Fawkes Development Version
fawkes::WebRequest Class Reference

Web request meta data carrier. More...

#include <>>

Public Types

enum  Method {
  METHOD_CONNECT, METHOD_DELETE, METHOD_GET, METHOD_HEAD,
  METHOD_OPTIONS, METHOD_POST, METHOD_PUT, METHOD_TRACE,
  METHOD_PATCH
}
 HTTP transfer methods. More...
 
enum  HttpVersion { HTTP_VERSION_1_0, HTTP_VERSION_1_1 }
 HTTP version. More...
 

Public Member Functions

 WebRequest (const char *uri)
 Constructor. More...
 
 ~WebRequest ()
 Destructor. More...
 
const std::string & url () const
 Get URL. More...
 
const std::string & uri () const
 Get URI. More...
 
Method method () const
 Get HTTP transfer method. More...
 
const char * method_str () const
 Get method as string. More...
 
HttpVersion http_version () const
 Get HTTP version. More...
 
const char * http_version_str () const
 Get HTTP version as string. More...
 
const Timetime () const
 Get request time. More...
 
const std::string & user () const
 Get name of authenticated user (basic auth). More...
 
const std::string & client_addr () const
 Get client address as string. More...
 
const std::map< std::string, std::string > & cookies () const
 Get map of cookies. More...
 
std::string cookie (std::string &key) const
 Get specific cookie. More...
 
bool has_cookie (std::string key) const
 Check if the named cookie has been received. More...
 
const std::map< std::string, std::string > & post_values () const
 Get map of POST values. More...
 
std::string post_value (std::string &key) const
 Get specific POST value. More...
 
std::string post_value (const char *key) const
 Get specific POST value. More...
 
bool has_post_value (std::string key) const
 Check if the named post value has been received. More...
 
const std::map< std::string, std::string > & get_values () const
 Get map of GET values. More...
 
std::string get_value (std::string &key) const
 Get specific GET value. More...
 
std::string get_value (const char *key) const
 Get specific GET value. More...
 
bool has_get_value (std::string key) const
 Check if the named get value has been received. More...
 
const std::map< std::string, std::string > & headers () const
 Get map of header values. More...
 
std::string header (std::string &key) const
 Header specific header value. More...
 
std::string header (const char *key) const
 Get specific header value. More...
 
bool has_header (std::string key) const
 Check if the named header value has been received. More...
 
void set_cookie (const std::string &key, const std::string &value)
 Set a cookie. More...
 
void set_post_value (const char *key, const char *data, size_t size)
 Set a POST value. More...
 
void set_get_value (const std::string &key, const std::string &value)
 Set a GET value. More...
 
void set_header (const std::string &key, const std::string &value)
 Set a header value. More...
 
std::string path_arg (const std::string &what) const
 Get a path argument. More...
 
void set_path_args (std::map< std::string, std::string > &&args)
 Set path arguments. More...
 
const std::string & body () const
 Get body of request. More...
 
void increment_reply_size (size_t increment_by)
 Increment reply bytes counter. More...
 
size_t reply_size () const
 Get number of bytes actually sent out so far. More...
 
WebReply::Code reply_code () const
 Get HTTP code of reply. More...
 
void set_reply_code (WebReply::Code code)
 Set HTTP code of the final reply. More...
 

Protected Member Functions

void set_cookies (const std::map< std::string, std::string > &cookies)
 Set cookie map. More...
 
void set_body (const char *data, size_t data_size)
 Set request body. More...
 
void addto_body (const char *data, size_t data_size)
 Add to request body. More...
 
void finish_body ()
 Finalize body handling. More...
 

Detailed Description

Web request meta data carrier.

For incoming web requests this class is instantiate to carry the necessary information for carriers like URL, request method, or cookie and POST form values.

Author
Tim Niemueller

Definition at line 41 of file request.h.

Member Enumeration Documentation

◆ HttpVersion

HTTP version.

Definition at line 60 of file request.h.

◆ Method

HTTP transfer methods.

Enumerator
METHOD_CONNECT 

CONNECT.

METHOD_DELETE 

DELETE.

METHOD_GET 

GET.

METHOD_HEAD 

HEAD.

METHOD_OPTIONS 

OPTIONS.

METHOD_POST 

POST.

METHOD_PUT 

PUT.

METHOD_TRACE 

TRACE.

METHOD_PATCH 

PATCH.

Definition at line 47 of file request.h.

Constructor & Destructor Documentation

◆ WebRequest()

fawkes::WebRequest::WebRequest ( const char *  uri)

Constructor.

Parameters
uriURI of the request

Definition at line 78 of file request.cpp.

◆ ~WebRequest()

fawkes::WebRequest::~WebRequest ( )

Destructor.

Definition at line 166 of file request.cpp.

Member Function Documentation

◆ addto_body()

void fawkes::WebRequest::addto_body ( const char *  data,
size_t  data_size 
)
protected

Add to request body.

The data is copied as is without assuming a human-readable string or even just zero-termination.

Parameters
datadata to copy
data_sizesize in bytes of @p data

Definition at line 209 of file request.cpp.

◆ body()

const std::string& fawkes::WebRequest::body ( ) const
inline

Get body of request.

Returns
The data that was received with the request. This is not set if we receive a form submission. The values will be available as POST values then. Note that this is not necesarily a printable string (or zero-terminated)

Definition at line 330 of file request.h.

Referenced by XmlRpcRequestProcessor::process_request(), and fawkes::WebviewRestApi::process_request().

◆ client_addr()

const std::string& fawkes::WebRequest::client_addr ( ) const
inline

Get client address as string.

Returns
client address as string

Definition at line 118 of file request.h.

Referenced by fawkes::WebviewAccessLog::log().

◆ cookie()

std::string fawkes::WebRequest::cookie ( std::string &  key) const
inline

Get specific cookie.

Parameters
keykey of the cookie
Returns
value of cookie or empty string if not set

Definition at line 135 of file request.h.

◆ cookies()

const std::map<std::string, std::string>& fawkes::WebRequest::cookies ( ) const
inline

Get map of cookies.

Returns
map of cookies.

Definition at line 126 of file request.h.

Referenced by set_cookies().

◆ finish_body()

void fawkes::WebRequest::finish_body ( )
protected

Finalize body handling.

Check for zero termination of body, and if it does not exist, add it.

Definition at line 218 of file request.cpp.

◆ get_value() [1/2]

std::string fawkes::WebRequest::get_value ( std::string &  key) const
inline

Get specific GET value.

Parameters
keykey of the get value
Returns
value of get value or empty string if not set

Definition at line 199 of file request.h.

◆ get_value() [2/2]

std::string fawkes::WebRequest::get_value ( const char *  key) const
inline

Get specific GET value.

Parameters
keykey of the get value
Returns
value of get value or empty string if not set

Definition at line 209 of file request.h.

◆ get_values()

const std::map<std::string, std::string>& fawkes::WebRequest::get_values ( ) const
inline

Get map of GET values.

Returns
map of GET values.

Definition at line 190 of file request.h.

Referenced by fawkes::WebviewRestApi::process_request().

◆ has_cookie()

bool fawkes::WebRequest::has_cookie ( std::string  key) const
inline

Check if the named cookie has been received.

Parameters
keykey of the requested cookie
Returns
true if the cookie was set, false otherwise

Definition at line 145 of file request.h.

◆ has_get_value()

bool fawkes::WebRequest::has_get_value ( std::string  key) const
inline

Check if the named get value has been received.

Parameters
keykey of the requested get value
Returns
true if the get value was received, false otherwise

Definition at line 219 of file request.h.

◆ has_header()

bool fawkes::WebRequest::has_header ( std::string  key) const
inline

Check if the named header value has been received.

Parameters
keykey of the requested header
Returns
true if the header value was received, false otherwise

Definition at line 256 of file request.h.

Referenced by fawkes::WebviewAccessLog::log(), and MetricsRequestProcessor::process_request().

◆ has_post_value()

bool fawkes::WebRequest::has_post_value ( std::string  key) const
inline

Check if the named post value has been received.

Parameters
keykey of the post value
Returns
true if the post value was received, false otherwise

Definition at line 182 of file request.h.

◆ header() [1/2]

std::string fawkes::WebRequest::header ( std::string &  key) const
inline

Header specific header value.

Parameters
keykey of the header value
Returns
value of header value or empty string if not set

Definition at line 236 of file request.h.

Referenced by fawkes::WebviewAccessLog::log(), and MetricsRequestProcessor::process_request().

◆ header() [2/2]

std::string fawkes::WebRequest::header ( const char *  key) const
inline

Get specific header value.

Parameters
keykey of the header value
Returns
value of header value or empty string if not set

Definition at line 246 of file request.h.

◆ headers()

const std::map<std::string, std::string>& fawkes::WebRequest::headers ( ) const
inline

Get map of header values.

Returns
map of header values.

Definition at line 227 of file request.h.

◆ http_version()

HttpVersion fawkes::WebRequest::http_version ( ) const
inline

Get HTTP version.

Returns
HTTP protocol version

Definition at line 93 of file request.h.

◆ http_version_str()

const char * fawkes::WebRequest::http_version_str ( ) const

Get HTTP version as string.

Returns
HTTP version as string.

Definition at line 268 of file request.cpp.

Referenced by fawkes::WebviewAccessLog::log().

◆ increment_reply_size()

void fawkes::WebRequest::increment_reply_size ( size_t  increment_by)

Increment reply bytes counter.

Parameters
increment_bynumber of bytes sent

Definition at line 231 of file request.cpp.

Referenced by fawkes::dynamic_reply_data_cb().

◆ method()

Method fawkes::WebRequest::method ( ) const
inline

Get HTTP transfer method.

Returns
request's HTTP transfer method

Definition at line 84 of file request.h.

Referenced by fawkes::WebviewRouter< Handler >::find_handler(), XmlRpcRequestProcessor::process_request(), and fawkes::WebviewRestApi::process_request().

◆ method_str()

const char * fawkes::WebRequest::method_str ( ) const

Get method as string.

Returns
HTTP method as string

Definition at line 249 of file request.cpp.

References METHOD_CONNECT, METHOD_DELETE, METHOD_GET, METHOD_HEAD, METHOD_OPTIONS, METHOD_POST, METHOD_PUT, and METHOD_TRACE.

Referenced by fawkes::WebviewAccessLog::log().

◆ path_arg()

std::string fawkes::WebRequest::path_arg ( const std::string &  what) const
inline

Get a path argument.

Retrieves a named argument that was a token in the registration URL, e.g., retrieve "id" for "/item/{id}".

Parameters
whatwhat to retrieve
Returns
item passed in URL or empty string

Definition at line 305 of file request.h.

◆ post_value() [1/2]

std::string fawkes::WebRequest::post_value ( std::string &  key) const
inline

Get specific POST value.

Parameters
keykey of the post value
Returns
value of post value or empty string if not set

Definition at line 162 of file request.h.

◆ post_value() [2/2]

std::string fawkes::WebRequest::post_value ( const char *  key) const
inline

Get specific POST value.

Parameters
keykey of the post value
Returns
value of post value or empty string if not set

Definition at line 172 of file request.h.

◆ post_values()

const std::map<std::string, std::string>& fawkes::WebRequest::post_values ( ) const
inline

Get map of POST values.

Returns
map of POST values.

Definition at line 153 of file request.h.

◆ reply_code()

WebReply::Code fawkes::WebRequest::reply_code ( ) const

Get HTTP code of reply.

Returns
HTTP code of reply

Definition at line 290 of file request.cpp.

Referenced by fawkes::WebviewAccessLog::log().

◆ reply_size()

size_t fawkes::WebRequest::reply_size ( ) const

Get number of bytes actually sent out so far.

Returns
number of bytes sent

Definition at line 240 of file request.cpp.

Referenced by fawkes::WebviewAccessLog::log().

◆ set_body()

void fawkes::WebRequest::set_body ( const char *  data,
size_t  data_size 
)
protected

Set request body.

The data is copied as is without assuming a human-readable string or even just zero-termination.

Parameters
datadata to copy
data_sizesize in bytes of @p data

Definition at line 197 of file request.cpp.

◆ set_cookie()

void fawkes::WebRequest::set_cookie ( const std::string &  key,
const std::string &  value 
)
inline

Set a cookie.

Parameters
keykey of the cookie
valuevalue of the cookie

Definition at line 266 of file request.h.

◆ set_cookies()

void fawkes::WebRequest::set_cookies ( const std::map< std::string, std::string > &  cookies)
inlineprotected

Set cookie map.

Parameters
cookiescookies map

Definition at line 345 of file request.h.

References cookies().

◆ set_get_value()

void fawkes::WebRequest::set_get_value ( const std::string &  key,
const std::string &  value 
)
inline

Set a GET value.

Parameters
keykey of the cookie
valuevalue of the GET argument

Definition at line 283 of file request.h.

◆ set_header()

void fawkes::WebRequest::set_header ( const std::string &  key,
const std::string &  value 
)
inline

Set a header value.

Parameters
keykey of the cookie
valuevalue of the header argument

Definition at line 293 of file request.h.

◆ set_path_args()

void fawkes::WebRequest::set_path_args ( std::map< std::string, std::string > &&  args)
inline

Set path arguments.

Parameters
argspath arguments

Definition at line 319 of file request.h.

◆ set_post_value()

void fawkes::WebRequest::set_post_value ( const char *  key,
const char *  data,
size_t  size 
)

Set a POST value.

Parameters
keykey of the cookie
dataincoming data
sizesize in bytes of data
keykey of the value
datadata of the value
sizesize in bytes of data

Definition at line 180 of file request.cpp.

◆ set_reply_code()

void fawkes::WebRequest::set_reply_code ( WebReply::Code  code)

Set HTTP code of the final reply.

Parameters
codereply code

Definition at line 281 of file request.cpp.

◆ time()

const Time& fawkes::WebRequest::time ( ) const
inline

Get request time.

Returns
request time

Definition at line 102 of file request.h.

Referenced by fawkes::WebviewAccessLog::log().

◆ uri()

const std::string& fawkes::WebRequest::uri ( ) const
inline

Get URI.

Returns
URI

Definition at line 76 of file request.h.

Referenced by fawkes::WebviewAccessLog::log().

◆ url()

const std::string& fawkes::WebRequest::url ( ) const
inline

Get URL.

Returns
URL

Definition at line 68 of file request.h.

Referenced by fawkes::WebviewRouter< Handler >::find_handler().

◆ user()

const std::string& fawkes::WebRequest::user ( ) const
inline

Get name of authenticated user (basic auth).

Returns
name of authenticated user or empty if non-protected URL

Definition at line 110 of file request.h.

Referenced by fawkes::WebviewAccessLog::log().


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