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

class answer provides easy means to set an HTTP answer and means to sent it back to a proto_connexion object More...

#include <answer.hpp>

Public Member Functions

 answer ()
 class constructor
 
 answer (const answer &ref)
 copy constructor
 
 answer (answer &&ref) noexcept=default
 move constructor
 
answeroperator= (const answer &ref)
 assignment copy operator
 
answeroperator= (answer &&ref) noexcept=default
 assignment move operator
 
 ~answer ()=default
 destructor
 
void clear ()
 clear all information from the object
 
void set_status (unsigned int status_code)
 set answer status code and reason [MANDATORY]
 
void set_reason (const std::string &reason_phrase)
 set reason [optional]
 
void set_version (unsigned int maj, unsigned int min)
 set version info [MANDATORY]
 
void add_cookie (const std::string &key, const std::string &value)
 add cookie to the answer [optional]
 
void add_body (const std::string &key)
 adds the body to the answer [optional] More...
 
void drop_body_keep_header ()
 removes the body keeping header untouched (Content-Length in particular)
 
void set_attribute (const std::string &key, const std::string &value)
 set a given attribute to the HTTP header
 
void add_attribute_member (const std::string &key, const std::string &value)
 
bool is_valid () const
 whether the minimal parameters have been set
 
unsigned int get_status_code () const
 get answer status code and reason
 
const std::string get_reason () const
 get reason
 
unsigned int get_maj_version () const
 get integer part of the version info
 
unsigned int get_min_version () const
 get decimal part of the version info
 
const std::string get_body () const
 get the current body of the answer
 
bool find_attribute (const std::string &key, std::string &value) const
 
void write (proto_connexion &output)
 send the answer
 

Detailed Description

class answer provides easy means to set an HTTP answer and means to sent it back to a proto_connexion object

Note
the main consumers of class answer are objects from responder class and its inherited classes

Member Function Documentation

◆ add_attribute_member()

void answer::add_attribute_member ( const std::string &  key,
const std::string &  value 
)

add an attribute to a possibly already existing message header

Note
according to RFC1945: "Multiple HTTP-header fields with the same field-name may be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It must be possible to combine the multiple header fields into one "field- name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma. Multiple HTTP-header fields with the same field-name may be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It must be possible to combine the multiple header fields into one "field- name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma." This is the way add_attribute_member behaves. If the given key already exists, the given value is added to the existing value to form a new CSV f

◆ add_body()

void answer::add_body ( const std::string &  key)

adds the body to the answer [optional]

Note
this also set Content-Length accordingly

◆ find_attribute()

bool answer::find_attribute ( const std::string &  key,
std::string &  value 
) const

retrieve the value of an attribute of the HTTP answer

Parameters
[in]keyis the key's attribute to look for
[out]valueis the associated value of the attribute if such attribute exists
Returns
true if the requested attribute has been found in this request

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