40#include "webdar_tools.hpp"
41#include "exceptions.hpp"
42#include "proto_connexion.hpp"
76 void set_status(
unsigned int status_code) { status = status_code; };
79 void set_reason(
const std::string & reason_phrase) { reason = reason_phrase; };
82 void set_version(
unsigned int maj,
unsigned int min) { maj_vers = maj; min_vers = min; };
85 void add_cookie(
const std::string & key,
const std::string & value);
90 void add_body(
const std::string & key);
96 void set_attribute(
const std::string & key,
const std::string & value) { attributes[webdar_tools_to_canonical_case(key)] = value; };
142 const std::string
get_body()
const {
return body; };
149 bool find_attribute(
const std::string & key, std::string & value)
const;
160 unsigned int maj_vers;
161 unsigned int min_vers;
162 std::map<std::string, std::string> attributes;
166 mutable std::map<std::string, std::string>::const_iterator next_read;
169 void reset_read_next_attribute()
const;
176 bool read_next_attribute(std::string & key, std::string & value)
const;
179 void copy_from(
const answer & ref);
class answer provides easy means to set an HTTP answer and means to sent it back to a proto_connexion...
Definition: answer.hpp:49
void drop_body_keep_header()
removes the body keeping header untouched (Content-Length in particular)
Definition: answer.hpp:93
answer & operator=(const answer &ref)
assignment copy operator
Definition: answer.hpp:61
bool find_attribute(const std::string &key, std::string &value) const
Definition: answer.cpp:88
void clear()
clear all information from the object
Definition: answer.cpp:44
unsigned int get_min_version() const
get decimal part of the version info
Definition: answer.hpp:139
void set_reason(const std::string &reason_phrase)
set reason [optional]
Definition: answer.hpp:79
unsigned int get_status_code() const
get answer status code and reason
Definition: answer.hpp:130
const std::string get_body() const
get the current body of the answer
Definition: answer.hpp:142
void add_cookie(const std::string &key, const std::string &value)
add cookie to the answer [optional]
Definition: answer.cpp:54
answer(answer &&ref) noexcept=default
move constructor
void set_status(unsigned int status_code)
set answer status code and reason [MANDATORY]
Definition: answer.hpp:76
answer(const answer &ref)
copy constructor
Definition: answer.hpp:55
void add_attribute_member(const std::string &key, const std::string &value)
Definition: answer.cpp:74
answer()
class constructor
Definition: answer.hpp:52
bool is_valid() const
whether the minimal parameters have been set
Definition: answer.cpp:83
void set_attribute(const std::string &key, const std::string &value)
set a given attribute to the HTTP header
Definition: answer.hpp:96
~answer()=default
destructor
void add_body(const std::string &key)
adds the body to the answer [optional]
Definition: answer.cpp:68
void write(proto_connexion &output)
send the answer
Definition: answer.cpp:102
unsigned int get_maj_version() const
get integer part of the version info
Definition: answer.hpp:136
const std::string get_reason() const
get reason
Definition: answer.hpp:133
void set_version(unsigned int maj, unsigned int min)
set version info [MANDATORY]
Definition: answer.hpp:82
buffers data from a TCP connexion, this is a pure virtual class
Definition: proto_connexion.hpp:41