.. index:: pair: class; EE::Network::Http::Request .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request: class EE::Network::Http::Request ================================ .. toctree:: :hidden: enum_EE_Network_Http_Request_Method.rst enum_EE_Network_Http_Request_Status.rst Overview ~~~~~~~~ Define a HTTP request. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class Request { public: // typedefs typedef std::function`&http, const Http::Request&:ref:`request`, const :ref:`Http::Response`&response, const :ref:`Status`&status, std::size_t totalBytes, std::size_t currentBytes)> :ref:`ProgressCallback`; typedef std::map :target:`FieldTable`; // enums enum :ref:`Method`; enum :ref:`Status`; // construction :ref:`Request`( const std::string& uri = "/", :ref:`Method` method = :ref:`Get`, const std::string& body = "", bool validateCertificate = true, bool validateHostname = true, bool followRedirect = true, bool compressedResponse = false ); // methods static :ref:`Method` :ref:`methodFromString`(std::string methodString); static std::string :ref:`methodToString`(const :ref:`Method`& method); void :ref:`setField`(const std::string& field, const std::string& value); void :ref:`setHeader`(const std::string& field, const std::string& value); bool :ref:`hasField`(const std::string& field) const; const std::string& :ref:`getField`(const std::string& field) const; void :ref:`setMethod`(:ref:`Method` method); void :ref:`setUri`(const std::string& uri); void :ref:`setHttpVersion`(unsigned int major, unsigned int minor); void :ref:`setBody`(const std::string& body); const std::string& :ref:`getUri`() const; const :ref:`Method`& :ref:`getMethod`() const; const bool& :ref:`getValidateCertificate`() const; void :ref:`setValidateCertificate`(bool enable); const bool& :ref:`getValidateHostname`() const; void :ref:`setValidateHostname`(bool enable); const bool& :ref:`getFollowRedirect`() const; void :ref:`setFollowRedirect`(bool follow); const unsigned int& :ref:`getMaxRedirects`() const; void :ref:`setMaxRedirects`(unsigned int maxRedirects); void :ref:`setProgressCallback`(const :ref:`ProgressCallback`& progressCallback); const :ref:`ProgressCallback`& :ref:`getProgressCallback`() const; void :ref:`cancel`(); const bool& :ref:`isCancelled`() const; const bool& :ref:`isCompressedResponse`() const; void :ref:`setCompressedResponse`(const bool& compressedResponse); void :ref:`setContinue`(const bool& resume); const bool& :ref:`isContinue`() const; bool :ref:`isVerbose`() const; void :ref:`setVerbose`(bool verbose); }; .. _details-class_e_e_1_1_network_1_1_http_1_1_request: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Define a HTTP request. Typedefs -------- .. index:: pair: typedef; ProgressCallback .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a9aa6f4238c83b292327392a2e7b34153: .. ref-code-block:: cpp :class: doxyrest-title-code-block typedef std::function`&http, const Http::Request&:ref:`request`, const :ref:`Http::Response`&response, const :ref:`Status`&status, std::size_t totalBytes, std::size_t currentBytes)> ProgressCallback Definition of the current progress callback .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - http - The http client * - request - The http request * - status - The status of the progress event * - totalBytes - The total bytes of the document / files ( only available if Content-Length is returned, otherwise is 0 ) * - currentBytes - Current received total bytes .. rubric:: Returns: True if continue the request, false will cancel the current request. Construction ------------ .. index:: pair: function; Request .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1abd35c2d99f8f3e57fb3c6354128d2152: .. ref-code-block:: cpp :class: doxyrest-title-code-block Request( const std::string& uri = "/", :ref:`Method` method = :ref:`Get`, const std::string& body = "", bool validateCertificate = true, bool validateHostname = true, bool followRedirect = true, bool compressedResponse = false ) Default constructor This constructor creates a GET request, with the root :ref:`URI ` ("/") and an empty body. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - uri - Target :ref:`URI ` * - method - Method to use for the request * - body - Content of the request's body * - validateCertificate - Enables certificate validation for https request * - validateHostname - Enables hostname validation for https request * - followRedirect - Allow follor redirects to the request. * - compressedResponse - Set if the requested response should be compressed ( if available ) Methods ------- .. index:: pair: function; methodFromString .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1acf32ad48dc56e36ca59443c1726ef577: .. ref-code-block:: cpp :class: doxyrest-title-code-block static :ref:`Method` methodFromString(std::string methodString) .. rubric:: Returns: Method from a method name string. .. index:: pair: function; methodToString .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a7bf985675854f3caeebf4767cbb21d7e: .. ref-code-block:: cpp :class: doxyrest-title-code-block static std::string methodToString(const :ref:`Method`& method) .. rubric:: Returns: The method string from a method .. index:: pair: function; setField .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a3157c185b1ee7f8d57af3fcf3898475d: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setField(const std::string& field, const std::string& value) Set the value of a field The field is created if it doesn't exist. The name of the field is case insensitive. By default, a request doesn't contain any field (but the mandatory fields are added later by the HTTP client when sending the request). .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - field - Name of the field to set * - value - Value of the field .. index:: pair: function; setHeader .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a9787f19f17fa8663234857d8e9b7f04d: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setHeader(const std::string& field, const std::string& value) .. rubric:: See also: :ref:`setField ` .. index:: pair: function; hasField .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a5fa84d5f9b1d9799624c822045049835: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool hasField(const std::string& field) const Check if the request defines a field This function uses case-insensitive comparisons. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - field - Name of the field to test .. rubric:: Returns: True if the field exists, false otherwise .. index:: pair: function; getField .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1abbd8e3ebc79b7e5a5d3750f18c8f1f5e: .. ref-code-block:: cpp :class: doxyrest-title-code-block const std::string& getField(const std::string& field) const Get the value of a field If the field *field* is not found in the response header, the empty string is returned. This function uses case-insensitive comparisons. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - field - Name of the field to get .. rubric:: Returns: Value of the field, or empty string if not found .. index:: pair: function; setMethod .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1ad06bb521ef900e0f6eb046cf622a11f7: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setMethod(:ref:`Method` method) Set the request method See the Method enumeration for a complete list of all the availale methods. The method is :ref:`Http::Request::Get ` by default. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - method - Method to use for the request .. index:: pair: function; setUri .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1ad2a6a88d8a71c5666d3f80b26f8ac4b2: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setUri(const std::string& uri) Set the requested :ref:`URI ` The :ref:`URI ` is the resource (usually a web page or a file) that you want to get or post. The :ref:`URI ` is "/" (the root page) by default. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - uri - :ref:`URI ` to request, relative to the host .. index:: pair: function; setHttpVersion .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1aed2caa0843ae229af1f402a3729f3032: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setHttpVersion(unsigned int major, unsigned int minor) Set the HTTP version for the request The HTTP version is 1.0 by default. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - major - Major HTTP version number * - minor - Minor HTTP version number .. index:: pair: function; setBody .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1afe3ff3057ac367dce055db2a23989d10: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setBody(const std::string& body) Set the body of the request The body of a request is optional and only makes sense for POST requests. It is ignored for all other methods. The body is empty by default. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - body - Content of the body .. index:: pair: function; getUri .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a1abc8ca2d97642f9d046a5dc9d89d62d: .. ref-code-block:: cpp :class: doxyrest-title-code-block const std::string& getUri() const .. rubric:: Returns: The request Uri .. index:: pair: function; getMethod .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a2287315f6270abefd34c4e35aacf49c6: .. ref-code-block:: cpp :class: doxyrest-title-code-block const :ref:`Method`& getMethod() const .. rubric:: Returns: The request Method .. index:: pair: function; getValidateCertificate .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a35e978b26d1e4ec14e4b1b5ec310fb5b: .. ref-code-block:: cpp :class: doxyrest-title-code-block const bool& getValidateCertificate() const .. rubric:: Returns: If :ref:`SSL ` certificate validation is enabled .. index:: pair: function; setValidateCertificate .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a3f090723d95a9b3a1ab6f0dc28101e09: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setValidateCertificate(bool enable) Enable/disable :ref:`SSL ` certificate validation .. index:: pair: function; getValidateHostname .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a9e105a9902b83cfce3afe1141eb9d198: .. ref-code-block:: cpp :class: doxyrest-title-code-block const bool& getValidateHostname() const .. rubric:: Returns: If :ref:`SSL ` hostname validation is enabled .. index:: pair: function; setValidateHostname .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1ac04be0eb346a7cb955ae11e7b2c13647: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setValidateHostname(bool enable) Enable/disable :ref:`SSL ` hostname validation .. index:: pair: function; getFollowRedirect .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a398a5a3379fb2b9ebc4400599a7b0226: .. ref-code-block:: cpp :class: doxyrest-title-code-block const bool& getFollowRedirect() const .. rubric:: Returns: If requests follow redirects .. index:: pair: function; setFollowRedirect .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a0677de1694c24eb690443cdcdfd675fa: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setFollowRedirect(bool follow) Enables/Disables follow redirects .. index:: pair: function; getMaxRedirects .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1acef82c69087e37615f0d2212ae31bded: .. ref-code-block:: cpp :class: doxyrest-title-code-block const unsigned int& getMaxRedirects() const .. rubric:: Returns: The maximun number of redirects allowd if follow redirect is enabled. .. index:: pair: function; setMaxRedirects .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a59ed9f94fd7788a2587d17e3d6518128: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setMaxRedirects(unsigned int maxRedirects) Set the maximun number of redirects allowed if follow redirect is enabled. .. index:: pair: function; setProgressCallback .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a23aba5c892cd56782a070dee05faac00: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setProgressCallback(const :ref:`ProgressCallback`& progressCallback) Sets a progress callback .. index:: pair: function; getProgressCallback .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a608b39b4eb1dd7ed07c7eab15dcdda3a: .. ref-code-block:: cpp :class: doxyrest-title-code-block const :ref:`ProgressCallback`& getProgressCallback() const Get the progress callback .. index:: pair: function; cancel .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1aa266d790565a5c910364ecfac6421d5c: .. ref-code-block:: cpp :class: doxyrest-title-code-block void cancel() Cancels the current request if being processed .. index:: pair: function; isCancelled .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a6198bb783073b9595df4d047df39bc43: .. ref-code-block:: cpp :class: doxyrest-title-code-block const bool& isCancelled() const .. rubric:: Returns: True if the current request was cancelled .. index:: pair: function; isCompressedResponse .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1aa68db3f99785fe818a0e817265eaff16: .. ref-code-block:: cpp :class: doxyrest-title-code-block const bool& isCompressedResponse() const .. rubric:: Returns: If requests a compressed response .. index:: pair: function; setCompressedResponse .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a89ddcb71483da54ee37f2b847e1d39e7: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setCompressedResponse(const bool& compressedResponse) Set to request a compressed response from the server The returned response will be automatically decompressed by the client. .. index:: pair: function; setContinue .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a4a1016ea45eb8b7bd0bf91e28780c17e: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setContinue(const bool& resume) Resumes download if a file is already present .. index:: pair: function; isContinue .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a1f154ce9982c18ae779c29a8baa0b8a8: .. ref-code-block:: cpp :class: doxyrest-title-code-block const bool& isContinue() const .. rubric:: Returns: If must continue a download previously started. .. index:: pair: function; isVerbose .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a0db1e382a84aa1f77472064dfe4901ef: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool isVerbose() const .. rubric:: Returns: True if request is verbose logging .. index:: pair: function; setVerbose .. _doxid-class_e_e_1_1_network_1_1_http_1_1_request_1a823a991f0cd17d07ba9ce8bc31daa142: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setVerbose(bool verbose) Set verbose logging