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
}
 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...
 
const std::string & raw_post_data () const
 Get raw post data. 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_raw_post_data (const char *data, size_t data_size)
 Set raw post data. More...
 

Friends

class WebRequestDispatcher
 

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 42 of file request.h.

Member Enumeration Documentation

◆ HttpVersion

HTTP version.

Definition at line 59 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.

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 80 of file request.cpp.

References client_addr(), method(), METHOD_CONNECT, METHOD_DELETE, METHOD_GET, METHOD_HEAD, METHOD_OPTIONS, METHOD_POST, METHOD_PUT, METHOD_TRACE, and url().

◆ ~WebRequest()

fawkes::WebRequest::~WebRequest ( )

Destructor.

Definition at line 154 of file request.cpp.

Member Function Documentation

◆ client_addr()

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

Get client address as string.

Returns
client address as string

Definition at line 95 of file request.h.

Referenced by fawkes::WebviewAccessLog::log(), and WebRequest().

◆ 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 104 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 99 of file request.h.

Referenced by set_cookies().

◆ 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 151 of file request.h.

Referenced by WebviewBlackBoardRequestProcessor::process_request(), and WebviewPtzCamRequestProcessor::process_request().

◆ 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 160 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 146 of file request.h.

◆ 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 113 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 169 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 198 of file request.h.

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

◆ 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 141 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 180 of file request.h.

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

◆ 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 189 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 175 of file request.h.

◆ http_version()

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

Get HTTP version.

Returns
HTTP protocol version

Definition at line 82 of file request.h.

References http_version_str().

◆ http_version_str()

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

Get HTTP version as string.

Returns
HTTP version as string.

Definition at line 235 of file request.cpp.

Referenced by http_version(), and 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 196 of file request.cpp.

Referenced by fawkes::dynamic_reply_data_cb(), fawkes::dynamic_reply_free_cb(), and raw_post_data().

◆ method()

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

Get HTTP transfer method.

Returns
request's HTTP transfer method

Definition at line 77 of file request.h.

References method_str().

Referenced by XmlRpcRequestProcessor::process_request(), set_cookies(), and WebRequest().

◆ method_str()

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

Get method as string.

Returns
HTTP method as string

Definition at line 215 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(), and method().

◆ 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 123 of file request.h.

Referenced by ClipsWebRequestProcessor::process_request().

◆ 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 132 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 118 of file request.h.

◆ raw_post_data()

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

Get raw post data.

Returns
raw port data or empty string if none. Note that this is not necesarily a printable string (or zero-terminated)

Definition at line 230 of file request.h.

References increment_reply_size(), reply_code(), reply_size(), and set_reply_code().

Referenced by XmlRpcRequestProcessor::process_request().

◆ reply_code()

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

Get HTTP code of reply.

Returns
HTTP code of reply

Definition at line 259 of file request.cpp.

Referenced by fawkes::WebviewAccessLog::log(), and raw_post_data().

◆ 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 205 of file request.cpp.

Referenced by fawkes::WebviewAccessLog::log(), and raw_post_data().

◆ 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 205 of file request.h.

References set_post_value().

◆ 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 241 of file request.h.

References cookies(), method(), set_raw_post_data(), and url().

◆ 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 218 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 224 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 169 of file request.cpp.

Referenced by fawkes::dynamic_reply_free_cb(), and set_cookie().

◆ set_raw_post_data()

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

Set raw post data.

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 187 of file request.cpp.

Referenced by fawkes::dynamic_reply_free_cb(), and set_cookies().

◆ 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 249 of file request.cpp.

Referenced by fawkes::dynamic_reply_free_cb(), and raw_post_data().

◆ time()

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

Get request time.

Returns
request time

Definition at line 87 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 73 of file request.h.

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

◆ url()

◆ 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 91 of file request.h.

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


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