libzeep

PrevUpHomeNext

Class request

zeep::http::request

Synopsis

// In header: <zeep/http/request.hpp>


class request {
public:
  // types
  typedef header param;           
  typedef header cookie_directive;

  // construct/copy/destruct
  request(const std::string &, const std::string &, 
          std::tuple< int, int > = { 1, 0 }, std::vector< header > && = {}, 
          std::string && = {});
  request(const request &);
  request & operator=(const request &);

  // friend functions
  friend std::ostream & operator<<(std::ostream &, const request &);

  // public member functions
  void set_local_endpoint(boost::asio::ip::tcp::socket &);
  std::tuple< std::string, uint16_t > get_local_endpoint() const;
  std::tuple< int, int > get_version() const;
  void set_method(const std::string &);
  const std::string & get_method() const;
  std::string get_uri() const;
  void set_uri(const std::string &);
  std::string get_path() const;
  std::string get_query() const;
  std::string get_host() const;
  std::string get_remote_address() const;
  const std::string & get_payload() const;
  void set_payload(const std::string &);
  boost::posix_time::ptime get_timestamp() const;
  float get_accept(const char *) const;
  bool keep_alive() const;
  void set_header(const char *, const std::string &);
  auto get_headers() const;
  std::string get_header(const char *) const;
  void remove_header(const char *);
  std::string get_pathname() const;
  json::element get_credentials() const;
  void set_credentials(json::element &&);
  std::string get_parameter(const char *) const;
  std::string get_parameter(const char *, const std::string &) const;
  template<typename T, 
           typename std::enable_if_t< std::is_floating_point_v< T >, int > = 0> 
    T get_parameter(const char *, const T &) const;
  template<typename T, 
           typename std::enable_if_t< std::is_integral_v< T > and not std::is_same_v< T, bool >, int > = 0> 
    T get_parameter(const char *, const T &) const;
  template<typename T, 
           typename std::enable_if_t< std::is_same_v< T, bool >, int > = 0> 
    T get_parameter(const char *, const T &) const;
  std::multimap< std::string, std::string > get_parameters() const;
  file_param get_file_parameter(const char *) const;
  std::vector< file_param > get_file_parameters(const char *) const;
  bool has_parameter(const char *) const;
  std::string get_cookie(const char *) const;
  std::string get_cookie(const std::string &) const;
  void set_cookie(const char *, const std::string &);
  std::vector< boost::asio::const_buffer > to_buffers() const;
  std::locale & get_locale() const;
  void set_content(const std::string &, const std::string &);
  void set_header(const std::string &, const std::string &);
  std::tuple< std::string, bool > get_parameter_ex(const char *) const;

  // private member functions
  void set_remote_address(const std::string &);
};

Description

request contains the parsed original HTTP request as received by the server.

request public construct/copy/destruct

  1. request(const std::string & method, const std::string & uri, 
            std::tuple< int, int > version = { 1, 0 }, 
            std::vector< header > && headers = {}, std::string && payload = {});
  2. request(const request & req);
  3. request & operator=(const request & rhs);

request friend functions

  1. friend std::ostream & operator<<(std::ostream & io, const request & req);
    For debugging purposes.

request public member functions

  1. void set_local_endpoint(boost::asio::ip::tcp::socket & socket);
    Fetch the local address from the connected socket.
  2. std::tuple< std::string, uint16_t > get_local_endpoint() const;
  3. std::tuple< int, int > get_version() const;
    Get the HTTP version requested.
  4. void set_method(const std::string & method);
    Set the METHOD type (POST, GET, etc)
  5. const std::string & get_method() const;
    Return the METHOD type (POST, GET, etc)
  6. std::string get_uri() const;
    Return the original URI as requested.
  7. void set_uri(const std::string & uri);
    Set the URI.
  8. std::string get_path() const;
    Return the local path part of the request, after removing scheme, host and parameters.
  9. std::string get_query() const;
    Return the parameter or query string, the part after the first question mark.
  10. std::string get_host() const;
    Return the requested host.
  11. std::string get_remote_address() const;
    Get the address of the connecting remote.
  12. const std::string & get_payload() const;
    Return the payload.
  13. void set_payload(const std::string & payload);
    Set the payload.
  14. boost::posix_time::ptime get_timestamp() const;
    Return the time at which this request was received.
  15. float get_accept(const char * type) const;
    Return the value in the Accept header for type.
  16. bool keep_alive() const;
    Check for Connection: keep-alive header.
  17. void set_header(const char * name, const std::string & value);
    Set or replace a named header.
  18. auto get_headers() const;
    Return the list of headers.
  19. std::string get_header(const char * name) const;
    Return the named header.
  20. void remove_header(const char * name);
    Remove this header from the list of headers.
  21. std::string get_pathname() const;
    Return the path part of the requested URI.
  22. json::element get_credentials() const;
    Get the credentials. This is filled in if the request was validated.
  23. void set_credentials(json::element && credentials);
    Set the credentials for the request.
  24. std::string get_parameter(const char * name) const;
    Return the named parameter.

    Fetch parameters from a request, either from the URL or from the payload in case the request contains a url-encoded or multi-part content-type header

  25. std::string get_parameter(const char * name, const std::string & defaultValue) const;
    Return the value of the parameter named name or the defaultValue if this parameter was not found.
  26. template<typename T, 
             typename std::enable_if_t< std::is_floating_point_v< T >, int > = 0> 
      T get_parameter(const char * name, const T & defaultValue) const;
    Return the value of the parameter named name or the defaultValue if this parameter was not found.
  27. template<typename T, 
             typename std::enable_if_t< std::is_integral_v< T > and not std::is_same_v< T, bool >, int > = 0> 
      T get_parameter(const char * name, const T & defaultValue) const;
    Return the value of the parameter named name or the defaultValue if this parameter was not found.
  28. template<typename T, 
             typename std::enable_if_t< std::is_same_v< T, bool >, int > = 0> 
      T get_parameter(const char * name, const T & defaultValue) const;
    Return the value of the parameter named name or the defaultValue if this parameter was not found.
  29. std::multimap< std::string, std::string > get_parameters() const;
    Return a std::multimap of name/value pairs for all parameters.
  30. file_param get_file_parameter(const char * name) const;
    Return the info for a file parameter with name name.
  31. std::vector< file_param > get_file_parameters(const char * name) const;
    Return the info for all file parameters with name name.
  32. bool has_parameter(const char * name) const;
    Return whether the named parameter is present in the request.
  33. std::string get_cookie(const char * name) const;
    Return the value of HTTP Cookie with name name.
  34. std::string get_cookie(const std::string & name) const;
    Return the value of HTTP Cookie with name name.
  35. void set_cookie(const char * name, const std::string & value);
    Set the value of HTTP Cookie with name name to value.
  36. std::vector< boost::asio::const_buffer > to_buffers() const;
    Return the content of this request in a sequence of const_buffers.

    Can be used in code that sends HTTP requests

  37. std::locale & get_locale() const;
    Return the Accept-Language header value in the request as a std::locale object.
  38. void set_content(const std::string & text, const std::string & contentType);
    suppose we want to construct requests...
  39. void set_header(const std::string & name, const std::string & value);
    set a header
  40. std::tuple< std::string, bool > get_parameter_ex(const char * name) const;
    Return value and flag indicating the existence of a parameter named name.

request private member functions

  1. void set_remote_address(const std::string & address);

PrevUpHomeNext