• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Body</title>
5<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../index.html" title="Chapter 1. Boost.Beast">
8<link rel="up" href="../concepts.html" title="Concepts">
9<link rel="prev" href="../concepts.html" title="Concepts">
10<link rel="next" href="BodyReader.html" title="BodyReader">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="../concepts.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="BodyReader.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h3 class="title">
27<a name="beast.concepts.Body"></a><a class="link" href="Body.html" title="Body">Body</a>
28</h3></div></div></div>
29<p>
30        A <span class="bold"><strong>Body</strong></span> type is supplied as a template argument
31        to the <a class="link" href="../ref/boost__beast__http__message.html" title="http::message"><code class="computeroutput"><span class="identifier">message</span></code></a> class. It controls both
32        the type of the data member of the resulting message object, and the algorithms
33        used during parsing and serialization.
34      </p>
35<h5>
36<a name="beast.concepts.Body.h0"></a>
37        <span class="phrase"><a name="beast.concepts.Body.associated_types"></a></span><a class="link" href="Body.html#beast.concepts.Body.associated_types">Associated
38        Types</a>
39      </h5>
40<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
41<li class="listitem">
42            <a class="link" href="../ref/boost__beast__http__is_body.html" title="http::is_body"><code class="computeroutput"><span class="identifier">is_body</span></code></a>
43          </li>
44<li class="listitem">
45            <a class="link" href="BodyReader.html" title="BodyReader"><span class="emphasis"><em>BodyReader</em></span></a>
46          </li>
47<li class="listitem">
48            <a class="link" href="BodyWriter.html" title="BodyWriter"><span class="emphasis"><em>BodyWriter</em></span></a>
49          </li>
50</ul></div>
51<h5>
52<a name="beast.concepts.Body.h1"></a>
53        <span class="phrase"><a name="beast.concepts.Body.requirements"></a></span><a class="link" href="Body.html#beast.concepts.Body.requirements">Requirements</a>
54      </h5>
55<p>
56        In this table:
57      </p>
58<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
59<li class="listitem">
60            <code class="computeroutput"><span class="identifier">B</span></code> is a type meeting the
61            requirements of <span class="bold"><strong>Body</strong></span>.
62          </li>
63<li class="listitem">
64            <code class="computeroutput"><span class="identifier">m</span></code> is a value of type
65            <code class="computeroutput"><span class="identifier">message</span><span class="special">&lt;</span><span class="identifier">b</span><span class="special">,</span><span class="identifier">B</span><span class="special">,</span><span class="identifier">F</span><span class="special">&gt;</span></code>
66            where <code class="computeroutput"><span class="identifier">b</span></code> is a <code class="computeroutput"><span class="keyword">bool</span></code> value and <code class="computeroutput"><span class="identifier">F</span></code>
67            is a type meeting the requirements of <a class="link" href="Fields.html" title="Fields"><span class="emphasis"><em>Fields</em></span></a>.
68          </li>
69</ul></div>
70<div class="table">
71<a name="beast.concepts.Body.valid_expressions"></a><p class="title"><b>Table 1.37. Valid expressions</b></p>
72<div class="table-contents"><table class="table" summary="Valid expressions">
73<colgroup>
74<col>
75<col>
76<col>
77</colgroup>
78<thead><tr>
79<th>
80                <p>
81                  Expression
82                </p>
83              </th>
84<th>
85                <p>
86                  Type
87                </p>
88              </th>
89<th>
90                <p>
91                  Semantics, Pre/Post-conditions
92                </p>
93              </th>
94</tr></thead>
95<tbody>
96<tr>
97<td>
98                <p>
99                  <code class="computeroutput"><span class="identifier">B</span><span class="special">::</span><span class="identifier">value_type</span></code>
100                </p>
101              </td>
102<td>
103              </td>
104<td>
105                <p>
106                  The return type of the <code class="computeroutput"><span class="identifier">message</span><span class="special">::</span><span class="identifier">body</span></code>
107                  member function. If this is not movable or not copyable, the containing
108                  message will be not movable or not copyable.
109                </p>
110              </td>
111</tr>
112<tr>
113<td>
114                <p>
115                  <code class="computeroutput"><span class="identifier">B</span><span class="special">::</span><span class="identifier">reader</span></code>
116                </p>
117              </td>
118<td>
119              </td>
120<td>
121                <p>
122                  If present, indicates that the body can be parsed. The type must
123                  meet the requirements of <a class="link" href="BodyReader.html" title="BodyReader"><span class="emphasis"><em>BodyReader</em></span></a>.
124                  The implementation constructs an object of this type to obtain
125                  buffers into which parsed body octets are placed.
126                </p>
127              </td>
128</tr>
129<tr>
130<td>
131                <p>
132                  <code class="computeroutput"><span class="identifier">B</span><span class="special">::</span><span class="identifier">writer</span></code>
133                </p>
134              </td>
135<td>
136              </td>
137<td>
138                <p>
139                  If present, indicates that the body is serializable. The type must
140                  meet the requirements of <a class="link" href="BodyWriter.html" title="BodyWriter"><span class="emphasis"><em>BodyWriter</em></span></a>.
141                  The implementation constructs an object of this type to obtain
142                  buffers representing the message body for serialization.
143                </p>
144              </td>
145</tr>
146<tr>
147<td>
148<pre class="programlisting"><span class="identifier">B</span><span class="special">::</span><span class="identifier">size</span><span class="special">(</span>
149  <span class="identifier">B</span><span class="special">::</span><span class="identifier">value_type</span> <span class="identifier">body</span><span class="special">)</span>
150</pre>
151              </td>
152<td>
153                <p>
154                  <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">uint64_t</span></code>
155                </p>
156              </td>
157<td>
158                <p>
159                  This static member function is optional. It returns the payload
160                  size of <code class="computeroutput"><span class="identifier">body</span></code> in
161                  bytes not including any chunked transfer encoding. The return value
162                  may be zero, to indicate that the message is known to have no payload.
163                  The function shall not exit via an exception.
164                </p>
165                <p>
166                  When this function is present:
167                </p>
168                <p>
169                  * The function shall not fail
170                </p>
171                <p>
172                  * A call to <a class="link" href="../ref/boost__beast__http__message/payload_size.html" title="http::message::payload_size"><code class="computeroutput"><span class="identifier">message</span><span class="special">::</span><span class="identifier">payload_size</span></code></a> will return
173                  the same value as <code class="computeroutput"><span class="identifier">size</span></code>.
174                </p>
175                <p>
176                  * A call to <a class="link" href="../ref/boost__beast__http__message/prepare_payload.html" title="http::message::prepare_payload"><code class="computeroutput"><span class="identifier">message</span><span class="special">::</span><span class="identifier">prepare_payload</span></code></a> will remove
177                  "chunked" from the Transfer-Encoding field if it appears
178                  as the last encoding, and will set the Content-Length field to
179                  the returned value.
180                </p>
181                <p>
182                  Otherwise, when the function is omitted:
183                </p>
184                <p>
185                  * A call to <a class="link" href="../ref/boost__beast__http__message/payload_size.html" title="http::message::payload_size"><code class="computeroutput"><span class="identifier">message</span><span class="special">::</span><span class="identifier">payload_size</span></code></a> will return
186                  <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">none</span></code>.
187                </p>
188                <p>
189                  * A call to <a class="link" href="../ref/boost__beast__http__message/prepare_payload.html" title="http::message::prepare_payload"><code class="computeroutput"><span class="identifier">message</span><span class="special">::</span><span class="identifier">prepare_payload</span></code></a> will erase
190                  the Content-Length field, and add "chunked" as the last
191                  encoding in the Transfer-Encoding field if it is not already present.
192                </p>
193              </td>
194</tr>
195</tbody>
196</table></div>
197</div>
198<br class="table-break"><h5>
199<a name="beast.concepts.Body.h2"></a>
200        <span class="phrase"><a name="beast.concepts.Body.exemplar"></a></span><a class="link" href="Body.html#beast.concepts.Body.exemplar">Exemplar</a>
201      </h5>
202<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">Body</span>
203<span class="special">{</span>
204    <span class="comment">// The type of message::body when used</span>
205    <span class="keyword">struct</span> <span class="identifier">value_type</span><span class="special">;</span>
206
207    <span class="comment">/// The algorithm used during parsing</span>
208    <span class="keyword">class</span> <span class="identifier">reader</span><span class="special">;</span>
209
210    <span class="comment">/// The algorithm used during serialization</span>
211    <span class="keyword">class</span> <span class="identifier">writer</span><span class="special">;</span>
212
213    <span class="comment">/// Returns the body's payload size</span>
214    <span class="keyword">static</span>
215    <span class="identifier">std</span><span class="special">::</span><span class="identifier">uint64_t</span>
216    <span class="identifier">size</span><span class="special">(</span><span class="identifier">value_type</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">body</span><span class="special">);</span>
217<span class="special">};</span>
218
219<span class="keyword">static_assert</span><span class="special">(</span><span class="identifier">is_body</span><span class="special">&lt;</span><span class="identifier">Body</span><span class="special">&gt;::</span><span class="identifier">value</span><span class="special">,</span> <span class="string">""</span><span class="special">);</span>
220</pre>
221<h5>
222<a name="beast.concepts.Body.h3"></a>
223        <span class="phrase"><a name="beast.concepts.Body.models"></a></span><a class="link" href="Body.html#beast.concepts.Body.models">Models</a>
224      </h5>
225<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
226<li class="listitem">
227            <a class="link" href="../ref/boost__beast__http__basic_dynamic_body.html" title="http::basic_dynamic_body"><code class="computeroutput"><span class="identifier">basic_dynamic_body</span></code></a>
228          </li>
229<li class="listitem">
230            <a class="link" href="../ref/boost__beast__http__basic_file_body.html" title="http::basic_file_body"><code class="computeroutput"><span class="identifier">basic_file_body</span></code></a>
231          </li>
232<li class="listitem">
233            <a class="link" href="../ref/boost__beast__http__basic_string_body.html" title="http::basic_string_body"><code class="computeroutput"><span class="identifier">basic_string_body</span></code></a>
234          </li>
235<li class="listitem">
236            <a class="link" href="../ref/boost__beast__http__buffer_body.html" title="http::buffer_body"><code class="computeroutput"><span class="identifier">buffer_body</span></code></a>
237          </li>
238<li class="listitem">
239            <a class="link" href="../ref/boost__beast__http__empty_body.html" title="http::empty_body"><code class="computeroutput"><span class="identifier">empty_body</span></code></a>
240          </li>
241<li class="listitem">
242            <a class="link" href="../ref/boost__beast__http__span_body.html" title="http::span_body"><code class="computeroutput"><span class="identifier">span_body</span></code></a>
243          </li>
244<li class="listitem">
245            <a class="link" href="../ref/boost__beast__http__vector_body.html" title="http::vector_body"><code class="computeroutput"><span class="identifier">vector_body</span></code></a>
246          </li>
247</ul></div>
248</div>
249<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
250<td align="left"></td>
251<td align="right"><div class="copyright-footer">Copyright © 2016-2019 Vinnie
252      Falco<p>
253        Distributed under the Boost Software License, Version 1.0. (See accompanying
254        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
255      </p>
256</div></td>
257</tr></table>
258<hr>
259<div class="spirit-nav">
260<a accesskey="p" href="../concepts.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="BodyReader.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
261</div>
262</body>
263</html>
264