HTTP Response ============= This part of the documentation talks about the publicly accessible API of the HTTP Response objects. This section details the `Response Concept`_ requirements, the implemented and required Directives_, Modifiers_, and Wrappers_ that work with the HTTP Response objects. Response Concept ---------------- A type models the Response Concept if it models the `Message Concept`_ and also supports the following constructs. **Legend** :R: The response type. :r: An instance of R. :S: The string type. :s,e,g: Instances of S. :P: The port type. :p: An instance of P. :V: The version type. :v: An instance of v. :T: The status type. :t: An instance of T. :M: The status message type. :m: An instance of M. :U: An unsigned 16-bit int. :u: An instance of U. .. note:: In the table below, the namespace ``traits`` is an alias for ``boost::network::http::traits``. +-------------------------------------+----------+-----------------------------+ | Construct | Result | Description | +=====================================+==========+=============================+ | ``R::string_type`` | ``S`` | The nested ``string_type`` | | | | type. | +-------------------------------------+----------+-----------------------------+ | ``traits::version::type`` | ``V`` | The version type associated | | | | with R. | +-------------------------------------+----------+-----------------------------+ | ``traits::status::type`` | ``T`` | The status type associated | | | | with R. | +-------------------------------------+----------+-----------------------------+ | ``traits::status_message::type`` | ``M`` | The status message type | | | | associated with R. | +-------------------------------------+----------+-----------------------------+ | ``r << version(v)`` | ``R&`` | Sets the version of ``r``. | +-------------------------------------+----------+-----------------------------+ | ``r << status(t)`` | ``R&`` | Sets the status of ``r``. | +-------------------------------------+----------+-----------------------------+ | ``r << status_message(m)`` | ``R&`` | Sets the status message of | | | | ``r``. | +-------------------------------------+----------+-----------------------------+ | ``version(r, v)`` | ``void`` | Sets the version of ``r``. | +-------------------------------------+----------+-----------------------------+ | ``status(r, t)`` | ``void`` | Sets the status of ``r``. | +-------------------------------------+----------+-----------------------------+ | ``status_message(r, m)`` | ``void`` | Sets the status message of | | | | ``r``. | +-------------------------------------+----------+-----------------------------+ | ``S e = version(r)`` | **NA** | Get the version of ``r``. | +-------------------------------------+----------+-----------------------------+ | ``U u = status(r)`` | **NA** | Get the status of ``r``. | +-------------------------------------+----------+-----------------------------+ | ``S g = status_message(r)`` | **NA** | Get the status message of | | | | ``r``. | +-------------------------------------+----------+-----------------------------+ .. _Message Concept: message.html#message-concept Directives ---------- This section details the provided directives that are provided by :mod:`cpp-netlib`. The section was written to assume that an appropriately constructed response instance is either of the following: .. code-block:: c++ boost::network::http::basic_response< boost::network::http::tags::http_default_8bit_udp_resolve > response; // or boost::network::http::basic_response< boost::network::http::tags::http_server > response; The section also assumes that there following using namespace declaration is in effect: .. code-block:: c++ using namespace boost::network; Directives are meant to be used in the following manner: .. code-block:: c++ response << directive(...); .. warning:: There are four versions of directives, those that are applicable to messages that support narrow strings (``std::string``), those that are applicable to messages that support wide strings (``std::wstring``), those that are applicable to messages that support future-wrapped narrow and wide strings (``boost::shared_future`` and ``boost::shared_future``). The :mod:`cpp-netlib` implementation still does not convert wide strings into UTF-8 encoded narrow strings. This will be implemented in subsequent library releases. For now all the implemented directives are listed, even if some of them still do not implement things correctly. *unspecified* ``source(std::string const & source_)`` Create a source directive with a ``std::string`` as a parameter, to be set as the source of the response. *unspecified* ``source(std::wstring const & source_)`` Create a source directive with a ``std::wstring`` as a parameter, to be set as the source of the response. *unspecified* ``source(boost::shared_future const & source_)`` Create a source directive with a ``boost::shared_future`` as a parameter, to be set as the source of the response. *unspecified* ``source(boost::shared_future const & source_)`` Create a source directive with a ``boost::shared_future`` as a parameter, to be set as the source of the response. *unspecified* ``destination(std::string const & source_)`` Create a destination directive with a ``std::string`` as a parameter, to be set as the destination of the response. *unspecified* ``destination(std::wstring const & source_)`` Create a destination directive with a ``std::wstring`` as a parameter, to be set as the destination of the response. *unspecified* ``destination(boost::shared_future const & destination_)`` Create a destination directive with a ``boost::shared_future`` as a parameter, to be set as the destination of the response. *unspecified* ``destination(boost::shared_future const & destination_)`` Create a destination directive with a ``boost::shared_future`` as a parameter, to be set as the destination of the response. *unspecified* ``header(std::string const & name, std::string const & value)`` Create a header directive that will add the given name and value pair to the headers already associated with the response. In this case the name and values are both ``std::string``. *unspecified* ``header(std::wstring const & name, std::wstring const & value)`` Create a header directive that will add the given name and value pair to the headers already associated with the response. In this case the name and values are both ``std::wstring``. *unspecified* ``remove_header(std::string const & name)`` Create a remove_header directive that will remove all the occurences of the given name from the headers already associated with the response. In this case the name of the header is of type ``std::string``. *unspecified* ``remove_header(std::wstring const & name)`` Create a remove_header directive that will remove all the occurences of the given name from the headers already associated with the response. In this case the name of the header is of type ``std::wstring``. *unspecified* ``body(std::string const & body_)`` Create a body directive that will set the response's body to the given parameter. In this case the type of the body is an ``std::string``. *unspecified* ``body(std::wstring const & body_)`` Create a body directive that will set the response's body to the given parameter. In this case the type of the body is an ``std::wstring``. *unspecified* ``body(boost::shared_future const & body_)`` Create a body directive that will set the response's body to the given parameter. In this case the type of the body is an ``boost::shared_future``. *unspecified* ``body(boost::shared_future const & body_)`` Create a body directive that will set the response's body to the given parameter. In this case the type of the body is an ``boost::shared_future``. *unspecified* ``version(std::string const & version_)`` Create a version directive that will set the response's version to the given parameter. In this case the type of the version is an ``std::string``. Note that this version includes the full ``"HTTP/"`` string. *unspecified* ``version(std::wstring const & version_)`` Create a version directive that will set the response's version to the given parameter. In this case the type of the version is an ``std::wstring``. Note that this version includes the full ``"HTTP/"`` string. *unspecified* ``version(boost::shared_future const & version_)`` Create a version directive that will set the response's version to the given parameter. In this case the type of the version is an ``boost::shared_future``. Note that this version includes the full ``"HTTP/"`` string. *unspecified* ``version(boost::shared_future const & version_)`` Create a version directive that will set the response's version to the given parameter. In this case the type of the version is an ``boost::shared_future``. Note that this version includes the full ``"HTTP/"`` string. *unspecified* ``status_message(std::string const & status_message_)`` Create a status_message directive that will set the response's status_message to the given parameter. In this case the type of the status_message is an ``std::string``. Note that this status_message includes the full ``"HTTP/"`` string. *unspecified* ``status_message(std::wstring const & status_message_)`` Create a status_message directive that will set the response's status_message to the given parameter. In this case the type of the status_message is an ``std::wstring``. Note that this status_message includes the full ``"HTTP/"`` string. *unspecified* ``status_message(boost::shared_future const & status_message_)`` Create a status_message directive that will set the response's status_message to the given parameter. In this case the type of the status_message is an ``boost::shared_future``. Note that this status_message includes the full ``"HTTP/"`` string. *unspecified* ``status_message(boost::shared_future const & status_message_)`` Create a status_message directive that will set the response's status_message to the given parameter. In this case the type of the status_message is an ``boost::shared_future``. Note that this status_message includes the full ``"HTTP/"`` string. *unspecified* ``status(boost::uint16_t status_)`` Create a status directive that will set the response's status to the given parameter. In this case the type of ``status_`` is ``boost::uint16_t``. *unspecified* ``status(boost::shared_future const & status_)`` Create a status directive that will set the response's status to the given parameter. In this case the type of ``status_`` is ``boost::shared_future``. Modifiers --------- This section details the provided modifiers that are provided by :mod:`cpp-netlib`. ``template inline void source(basic_response & response, typename string::type const & source_)`` Modifies the source of the given ``response``. The type of ``source_`` is dependent on the ``Tag`` specialization of ``basic_response``. ``template inline void source(basic_response & response, boost::shared_future::type> const & source_)`` Modifies the source of the given ``response``. The type of ``source_`` is dependent on the ``Tag`` specialization of ``basic_response``. ``template inline void destination(basic_response & response, typename string::type const & destination_)`` Modifies the destination of the given ``response``. The type of ``destination_`` is dependent on the ``Tag`` specialization of ``basic_response``. ``template inline void destination(basic_response & response, boost::shared_future::type> const & destination_)`` Modifies the destination of the given ``response``. The type of ``destination_`` is dependent on the ``Tag`` specialization of ``basic_response``. ``template inline void add_header(basic_response & response, typename string::type const & name, typename string::type const & value)`` Adds a header to the given ``response``. The type of the ``name`` and ``value`` parameters are dependent on the ``Tag`` specialization of ``basic_response``. ``template inline void remove_header(basic_response & response, typename string::type const & name)`` Removes a header from the given ``response``. The type of the ``name`` parameter is dependent on the ``Tag`` specialization of ``basic_response``. ``template inline void headers(basic_response & response, typename headers_container >::type const & headers_)`` Sets the whole headers contained in ``response`` as the given parameter ``headers_``. ``template inline void headers(basic_response & response, boost::shared_future >::type> const & headers_)`` Sets the whole headers contained in ``response`` as the given parameter ``headers_``. ``template inline void clear_headers(basic_response & response)`` Removes all headers from the given ``response``. ``template inline void body(basic_response & response, typename string::type const & body_)`` Modifies the body of the given ``response``. The type of ``body_`` is dependent on the ``Tag`` specialization of ``basic_response``. ``template inline void body(basic_response & response, boost::shared_future::type> const & body_)`` Modifies the body of the given ``response``. The type of ``body_`` is dependent on the ``Tag`` specialization of ``basic_response``. ``template inline void version(basic_response & response, typename traits::version >::type const & version_)`` Modifies the version of the given ``response``. The type of ``version_`` is dependent on the ``Tag`` specialization of ``basic_response``. ``template inline void status(basic_response & response, typename traits::status >::type const & status_)`` Modifies the status of the given ``response``. The type of ``status_`` is dependent on the ``Tag`` specialization of ``basic_response``. ``template inline void status_message(basic_response & response, typename traits::status_message >::type const & status_message_)`` Modifies the status message of the given ``response``. The type of ``status_message_`` is dependent on the ``Tag`` specialization of ``basic_response``. Wrappers -------- This section details the provided response wrappers that come with :mod:`cpp-netlib`. Wrappers are used to convert a message into a different type, usually providing accessor operations to retrieve just part of the message. This section assumes that the following using namespace directives are in effect: .. code-block:: c++ using namespace boost::network; using namespace boost::network::http; ``template `` *unspecified* ``source(basic_response const & response)`` Returns a wrapper convertible to ``typename string::type`` that provides the source of a given response. ``template `` *unspecified* ``destination(basic_response const & response)`` Returns a wrapper convertible to ``typename string::type`` that provides the destination of a given response. ``template `` *unspecified* ``headers(basic_response const & response)`` Returns a wrapper convertible to ``typename headers_range >::type`` or ``typename basic_response::headers_container_type`` that provides the headers of a given response. ``template `` *unspecified* ``body(basic_response const & response)`` Returns a wrapper convertible to ``typename string::type`` that provides the body of a given response. ``template `` *unspecified* ``version(basic_response const & response)`` Returns a wrapper convertible to ``typename string::type`` that provides the version of the given response. ``template `` *unspecified* ``status(basic_response const & response)`` Returns a wrapper convertible to ``typename string::type`` that provides the status of the given response. ``template `` *unspecified* ``status_message(basic_response const & response)`` Returns a wrapper convertible to ``typename string::type`` that provides the status message of the given response.