libzeep

PrevUpHomeNext

Class reply

zeep::http::reply — the class containing all to generate a HTTP reply

Synopsis

// 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);
};

Description

Create a HTTP reply, should be either HTTP 1.0 or 1.1

reply public construct/copy/destruct

  1. reply(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.
  2. reply(status_type status, std::tuple< int, int > version, 
          std::vector< header > && headers, std::string && payload);
  3. reply(const reply & rhs);
  4. reply & operator=(const reply &);
  5. ~reply();

reply friend functions

  1. friend std::ostream & operator<<(std::ostream & os, const reply & rep);
    for debugging

reply public member functions

  1. void reset();
  2. void set_version(int version_major, int version_minor);
  3. void set_version(std::tuple< int, int > version);
  4. void set_header(const std::string & name, const std::string & value);
    Add a header with name name and value value.
  5. std::string get_header(const std::string & name) const;
    Return the value of the header with name name.
  6. void remove_header(const std::string & name);
    Remove the header with name name from the list of headers.
  7. void set_cookie(const char * name, const std::string & value, 
                    std::initializer_list< cookie_directive > directives = {});
    Set a cookie.
  8. void set_delete_cookie(const char * name);
    Set a header to delete the name cookie.
  9. std::string get_cookie(const char * name) const;
    Get a cookie.
  10. std::string get_content_type() const;
  11. void set_content_type(const std::string & type);
  12. void set_content(xml::document & doc);
    Set the content and the content-type header depending on the content of doc (might be xhtml)
  13. void set_content(const xml::element & data);
    Set the content and the content-type header to text/xml.
  14. void set_content(const json::element & json);
    Set the content and the content-type header based on JSON data.
  15. void set_content(const std::string & data, const std::string & contentType);
    Set the content and the content-type header.
  16. void set_content(const char * data, size_t size, 
                     const std::string & contentType);
    Set the content by copying data and the content-type header.
  17. 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.

  18. const std::string & get_content() const;

    return the content, only useful if the content was set with some constant string data.

  19. std::vector< boost::asio::const_buffer > to_buffers() const;
    return the content of the reply as an array of boost::asio::const_buffer objects
  20. std::vector< boost::asio::const_buffer > data_to_buffers();
    for istream data, if the returned buffer array is empty, the data is done
  21. void set_status(status_type status);
  22. status_type get_status() const;
  23. size_t size() const;
    return the size of the reply, only correct if the reply is fully memory based (no streams)
  24. bool get_chunked() const;
    Return true if the content will be sent chunked encoded.

reply public static functions

  1. static reply stock_reply(status_type inStatus);
    Create a standard reply based on a HTTP status code.
  2. static reply stock_reply(status_type inStatus, const std::string & info);
  3. static reply redirect(const std::string & location);
    Create a standard redirect reply with the specified location.
  4. static reply redirect(const std::string & location, status_type status);

PrevUpHomeNext