1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
|
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.
.. note:: The HTTP server response object is a POD type, which doesn't support
any of the following details. There are only a few fields available in the
HTTP server response type, which can be seen in
``boost/network/protocol/http/impl/response.ipp``.
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<R>::type`` | ``V`` | The version type associated |
| | | with R. |
+-------------------------------------+----------+-----------------------------+
| ``traits::status<R>::type`` | ``T`` | The status type associated |
| | | with R. |
+-------------------------------------+----------+-----------------------------+
| ``traits::status_message<R>::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: ../in_depth/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<std::string>`` and
``boost::shared_future<std::wstring>``).
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<std::string> const & source_)``
Create a source directive with a ``boost::shared_future<std::string>`` as a parameter, to be set
as the source of the response.
*unspecified* ``source(boost::shared_future<std::wstring> const & source_)``
Create a source directive with a ``boost::shared_future<std::wstring>`` 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<std::string> const & destination_)``
Create a destination directive with a ``boost::shared_future<std::string>`` as a parameter, to be set
as the destination of the response.
*unspecified* ``destination(boost::shared_future<std::wstring> const & destination_)``
Create a destination directive with a ``boost::shared_future<std::wstring>`` 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<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 ``boost::shared_future<std::string>``.
*unspecified* ``body(boost::shared_future<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 ``boost::shared_future<std::wstring>``.
*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<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 ``boost::shared_future<std::string>``.
Note that this version includes the full ``"HTTP/"`` string.
*unspecified* ``version(boost::shared_future<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 ``boost::shared_future<std::wstring>``.
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<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 ``boost::shared_future<std::string>``.
Note that this status_message includes the full ``"HTTP/"`` string.
*unspecified* ``status_message(boost::shared_future<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 ``boost::shared_future<std::wstring>``.
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<boost::uint16_t> 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<boost::uint16_t>``.
Modifiers
---------
This section details the provided modifiers that are provided by
:mod:`cpp-netlib`.
``template <class Tag> inline void source(basic_response<Tag> & response, typename string<Tag>::type const & source_)``
Modifies the source of the given ``response``. The type of ``source_`` is
dependent on the ``Tag`` specialization of ``basic_response``.
``template <class Tag> inline void source(basic_response<Tag> & response, boost::shared_future<typename string<Tag>::type> const & source_)``
Modifies the source of the given ``response``. The type of ``source_`` is
dependent on the ``Tag`` specialization of ``basic_response``.
``template <class Tag> inline void destination(basic_response<Tag> & response, typename string<Tag>::type const & destination_)``
Modifies the destination of the given ``response``. The type of ``destination_`` is
dependent on the ``Tag`` specialization of ``basic_response``.
``template <class Tag> inline void destination(basic_response<Tag> & response, boost::shared_future<typename string<Tag>::type> const & destination_)``
Modifies the destination of the given ``response``. The type of ``destination_`` is
dependent on the ``Tag`` specialization of ``basic_response``.
``template <class Tag> inline void add_header(basic_response<Tag> & response, typename string<Tag>::type const & name, typename string<Tag>::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 <class Tag> inline void remove_header(basic_response<Tag> & response, typename string<Tag>::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 <class Tag> inline void headers(basic_response<Tag> & response, typename headers_container<basic_response<Tag> >::type const & headers_)``
Sets the whole headers contained in ``response`` as the given parameter
``headers_``.
``template <class Tag> inline void headers(basic_response<Tag> & response, boost::shared_future<typename headers_container<basic_response<Tag> >::type> const & headers_)``
Sets the whole headers contained in ``response`` as the given parameter
``headers_``.
``template <class Tag> inline void clear_headers(basic_response<Tag> & response)``
Removes all headers from the given ``response``.
``template <class Tag> inline void body(basic_response<Tag> & response, typename string<Tag>::type const & body_)``
Modifies the body of the given ``response``. The type of ``body_`` is
dependent on the ``Tag`` specialization of ``basic_response``.
``template <class Tag> inline void body(basic_response<Tag> & response, boost::shared_future<typename string<Tag>::type> const & body_)``
Modifies the body of the given ``response``. The type of ``body_`` is
dependent on the ``Tag`` specialization of ``basic_response``.
``template <class Tag> inline void version(basic_response<Tag> & response, typename traits::version<basic_response<Tag> >::type const & version_)``
Modifies the version of the given ``response``. The type of ``version_`` is
dependent on the ``Tag`` specialization of ``basic_response``.
``template <class Tag> inline void status(basic_response<Tag> & response, typename traits::status<basic_response<Tag> >::type const & status_)``
Modifies the status of the given ``response``. The type of ``status_`` is
dependent on the ``Tag`` specialization of ``basic_response``.
``template <class Tag> inline void status_message(basic_response<Tag> & response, typename traits::status_message<basic_response<Tag> >::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 <class Tag>`` *unspecified* ``source(basic_response<Tag> const & response)``
Returns a wrapper convertible to ``typename string<Tag>::type`` that
provides the source of a given response.
``template <class Tag>`` *unspecified* ``destination(basic_response<Tag> const & response)``
Returns a wrapper convertible to ``typename string<Tag>::type`` that
provides the destination of a given response.
``template <class Tag>`` *unspecified* ``headers(basic_response<Tag> const & response)``
Returns a wrapper convertible to ``typename headers_range<basic_response<Tag>
>::type`` or ``typename basic_response<Tag>::headers_container_type`` that
provides the headers of a given response.
``template <class Tag>`` *unspecified* ``body(basic_response<Tag> const & response)``
Returns a wrapper convertible to ``typename string<Tag>::type`` that
provides the body of a given response.
``template <class Tag>`` *unspecified* ``version(basic_response<Tag> const & response)``
Returns a wrapper convertible to ``typename string<Tag>::type`` that
provides the version of the given response.
``template <class Tag>`` *unspecified* ``status(basic_response<Tag> const & response)``
Returns a wrapper convertible to ``typename string<Tag>::type`` that
provides the status of the given response.
``template <class Tag>`` *unspecified* ``status_message(basic_response<Tag> const & response)``
Returns a wrapper convertible to ``typename string<Tag>::type`` that
provides the status message of the given response.
|