![]() |
zeep::http::reply — the class containing all to generate a HTTP reply
// In header: <zeep/http/reply.hpp> class reply { public: // types typedef header cookie_directive; // construct/copy/destruct reply(status_type = internal_server_error, std::tuple< int, int > = { 1, 0 }); reply(status_type, std::tuple< int, int >, std::vector< header > &&, std::string &&); reply(const reply &); reply & operator=(const reply &); ~reply(); // friend functions friend std::ostream & operator<<(std::ostream &, const reply &); // public member functions void reset(); void set_version(int, int); void set_version(std::tuple< int, int >); void set_header(const std::string &, const std::string &); std::string get_header(const std::string &) const; void remove_header(const std::string &); void set_cookie(const char *, const std::string &, std::initializer_list< cookie_directive > = {}); void set_delete_cookie(const char *); std::string get_cookie(const char *) const; std::string get_content_type() const; void set_content_type(const std::string &); void set_content(xml::document &); void set_content(const xml::element &); void set_content(const json::element &); void set_content(const std::string &, const std::string &); void set_content(const char *, size_t, const std::string &); void set_content(std::istream *, const std::string &); const std::string & get_content() const; std::vector< boost::asio::const_buffer > to_buffers() const; std::vector< boost::asio::const_buffer > data_to_buffers(); void set_status(status_type); status_type get_status() const; size_t size() const; bool get_chunked() const; // public static functions static reply stock_reply(status_type); static reply stock_reply(status_type, const std::string &); static reply redirect(const std::string &); static reply redirect(const std::string &, status_type); };
Create a HTTP reply, should be either HTTP 1.0 or 1.1
reply
public
construct/copy/destructreply(status_type status = internal_server_error, std::tuple< int, int > version = { 1, 0 });Create a reply, default is HTTP 1.0. Use 1.1 if you want to use keep alive e.g.
reply(status_type status, std::tuple< int, int > version, std::vector< header > && headers, std::string && payload);
reply(const reply & rhs);
reply & operator=(const reply &);
~reply();
reply
friend functionsfriend std::ostream & operator<<(std::ostream & os, const reply & rep);for debugging
reply
public member functionsvoid reset();
void set_version(int version_major, int version_minor);
void set_version(std::tuple< int, int > version);
void set_header(const std::string & name, const std::string & value);Add a header with name name and value value.
std::string get_header(const std::string & name) const;Return the value of the header with name name.
void remove_header(const std::string & name);Remove the header with name name from the list of headers.
void set_cookie(const char * name, const std::string & value, std::initializer_list< cookie_directive > directives = {});Set a cookie.
void set_delete_cookie(const char * name);Set a header to delete the name cookie.
std::string get_cookie(const char * name) const;Get a cookie.
std::string get_content_type() const;
void set_content_type(const std::string & type);
void set_content(xml::document & doc);Set the content and the content-type header depending on the content of doc (might be xhtml)
void set_content(const xml::element & data);Set the content and the content-type header to text/xml.
void set_content(const json::element & json);Set the content and the content-type header based on JSON data.
void set_content(const std::string & data, const std::string & contentType);Set the content and the content-type header.
void set_content(const char * data, size_t size, const std::string & contentType);Set the content by copying data and the content-type header.
void set_content(std::istream * data, const std::string & contentType);
To send a stream of data, with unknown size (using chunked transfer). reply takes ownership of data and deletes it when done.
const std::string & get_content() const;
return the content, only useful if the content was set with some constant string data.
std::vector< boost::asio::const_buffer > to_buffers() const;return the content of the reply as an array of boost::asio::const_buffer objects
std::vector< boost::asio::const_buffer > data_to_buffers();for istream data, if the returned buffer array is empty, the data is done
void set_status(status_type status);
status_type get_status() const;
size_t size() const;return the size of the reply, only correct if the reply is fully memory based (no streams)
bool get_chunked() const;Return true if the content will be sent chunked encoded.
reply
public static functionsstatic reply stock_reply(status_type inStatus);Create a standard reply based on a HTTP status code.
static reply stock_reply(status_type inStatus, const std::string & info);
static reply redirect(const std::string & location);Create a standard redirect reply with the specified location.
static reply redirect(const std::string & location, status_type status);