Webdar 1.0.0
Web user interface to libdar
Public Member Functions | List of all members
request Class Reference

class holding fields of an HTTP request (method, URI, header, cookies, and so on) More...

#include <request.hpp>

Public Member Functions

 request (const std::shared_ptr< central_report > &log)
 The constructor.
 
 request (const request &ref)=default
 
 request (request &&ref) noexcept=default
 
requestoperator= (const request &ref)=default
 
requestoperator= (request &&ref) noexcept=default
 
void clear ()
 clear all fields of the request
 
bool try_reading (proto_connexion &input)
 
void read (proto_connexion &input)
 
const std::string & get_method () const
 obtains the method of the read request
 
void change_method (const std::string &val)
 manually change the method of the request
 
void post_to_get ()
 change POST request to a GET request, No modification for others
 
const uriget_uri () const
 obtains the URI of the read request
 
int get_maj_version () const
 obtains the MAJOR version string of the read request
 
int get_min_version () const
 obtains the MINOR version string of the read request
 
const std::string & get_body () const
 obtain the body of the read request
 
std::map< std::string, std::string > get_body_form () const
 
void add_cookie (const std::string &key, const std::string &value) const
 
bool find_cookie (const std::string &key, std::string &value) const
 lookup for a cookie
 
bool find_attribute (const std::string &key, std::string &value) const
 raw request header header access
 
unsigned int get_multipart_number () const
 analyse body as a MIME multipart component (RFC 1521) More...
 
std::map< troncon, tronconget_header_of_multipart (unsigned int num) const
 obtains the headers of multiparts once get_multipart_number() has been executed More...
 
troncon get_body_of_multipart (unsigned int num) const
 obtains the body of multiparts once get_multipart_number() has been executed More...
 
void fake_valid_request ()
 set the fields in consistent state to mimic a valid request More...
 

Detailed Description

class holding fields of an HTTP request (method, URI, header, cookies, and so on)

Examples
/home/denis/Webdar/webdar/src/html_form_input_file.hpp.

Member Function Documentation

◆ add_cookie()

void request::add_cookie ( const std::string &  key,
const std::string &  value 
) const

manually add a cookie to the request (should be used exceptionally)

Note
the semantic of a const method might sound strange here as we do modify the request object. Well, nothing's perfect... improvment may take place here, yes.

◆ fake_valid_request()

void request::fake_valid_request ( )

set the fields in consistent state to mimic a valid request

Note
used to convert body_builder class with static adopted child to static_body_builder class

◆ get_body_form()

map< string, string > request::get_body_form ( ) const

obtain the body splitted in as list of attribute-value pair

Note
this call can be used to analyse POST request's body in response to a form
this call should only be used when the Content-Type is application/x-www-form-urlencoded, if not an exception is thrown

◆ get_body_of_multipart()

troncon request::get_body_of_multipart ( unsigned int  num) const

obtains the body of multiparts once get_multipart_number() has been executed

Parameters
[in]numthe part number of the multipart in this request, first part is starting at index zero
Returns
the document inclosed in the multipart number "num" of the body

◆ get_header_of_multipart()

map< troncon, troncon > request::get_header_of_multipart ( unsigned int  num) const

obtains the headers of multiparts once get_multipart_number() has been executed

Parameters
[in]numthe part number of the multipart in this request, first part is starting at index zero
Returns
a map of key/value pair corresponding to the key/values pair found in the header the multipart number "num" found in the body first part is starting at index zero

◆ get_multipart_number()

unsigned int request::get_multipart_number ( ) const

analyse body as a MIME multipart component (RFC 1521)

Returns
the number of multipart found in the body of the request
Note
the request's header must have a header "Content-type: multipart/form-data; boundary=.....\r\n"
if the request is not properly formated or is not a multipart one, an exception_range is thrown

◆ read()

void request::read ( proto_connexion input)

read the next request from input connexion

Note
this method fills the internal fields (request line, header and body)
may throw exceptions of type exception_range and exception_input. the first mean that the request could not be read completely, the caller must either not catch this type of exception, or reply by a bad-request answer and close the connexion even in HTTP/1.1 because be could not completely read the request. Upon exception_input, the request could be read entirely, connexion can be maintained. The request code is to send in the answer is provided by this exception class.

◆ try_reading()

bool request::try_reading ( proto_connexion input)

try reading just enough data in order to determine the uri of the next request

Note
this method only fills the method and URI fields if data is available for that, in which case only, true is returned. get_method() and get_uri() can then be invoked to obtain the fields value.

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