1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>FieldsWriter</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="Fields.html" title="Fields"> 10<link rel="next" href="File.html" title="File"> 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="Fields.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="File.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.FieldsWriter"></a><a class="link" href="FieldsWriter.html" title="FieldsWriter">FieldsWriter</a> 28</h3></div></div></div> 29<p> 30 A <span class="bold"><strong>FieldsWriter</strong></span> provides a algorithm to obtain 31 a sequence of buffers representing the complete serialized HTTP/1 header 32 for a set of fields. The implementation constructs an instance of this type 33 when needed, and calls into it once to retrieve the buffers. 34 </p> 35<h5> 36<a name="beast.concepts.FieldsWriter.h0"></a> 37 <span class="phrase"><a name="beast.concepts.FieldsWriter.associated_types"></a></span><a class="link" href="FieldsWriter.html#beast.concepts.FieldsWriter.associated_types">Associated 38 Types</a> 39 </h5> 40<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 41 <a class="link" href="FieldsWriter.html" title="FieldsWriter"><span class="emphasis"><em>FieldsWriter</em></span></a> 42 </li></ul></div> 43<h5> 44<a name="beast.concepts.FieldsWriter.h1"></a> 45 <span class="phrase"><a name="beast.concepts.FieldsWriter.requirements"></a></span><a class="link" href="FieldsWriter.html#beast.concepts.FieldsWriter.requirements">Requirements</a> 46 </h5> 47<div class="warning"><table border="0" summary="Warning"> 48<tr> 49<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../doc/src/images/warning.png"></td> 50<th align="left">Warning</th> 51</tr> 52<tr><td align="left" valign="top"><p> 53 These requirements may undergo non-backward compatible changes in subsequent 54 versions. 55 </p></td></tr> 56</table></div> 57<p> 58 In this table: 59 </p> 60<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 61<li class="listitem"> 62 <code class="computeroutput"><span class="identifier">W</span></code> denotes a type that 63 meets the requirements of <span class="bold"><strong>FieldsWriter</strong></span>. 64 </li> 65<li class="listitem"> 66 <code class="computeroutput"><span class="identifier">F</span></code> denotes a <a class="link" href="Fields.html" title="Fields"><span class="emphasis"><em>Fields</em></span></a> 67 where <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">is_same</span><span class="special"><</span><span class="identifier">W</span><span class="special">,</span> <span class="identifier">F</span><span class="special">::</span><span class="identifier">writer</span><span class="special">>::</span><span class="identifier">value</span> <span class="special">==</span> 68 <span class="keyword">true</span></code>. 69 </li> 70<li class="listitem"> 71 <code class="computeroutput"><span class="identifier">a</span></code> is a value of type 72 <code class="computeroutput"><span class="identifier">W</span></code>. 73 </li> 74<li class="listitem"> 75 <code class="computeroutput"><span class="identifier">f</span></code> is a value of type 76 <code class="computeroutput"><span class="identifier">F</span></code>. 77 </li> 78<li class="listitem"> 79 <code class="computeroutput"><span class="identifier">v</span></code> is an <code class="computeroutput"><span class="keyword">unsigned</span></code> value representing the HTTP version. 80 </li> 81<li class="listitem"> 82 <code class="computeroutput"><span class="identifier">c</span></code> is an <code class="computeroutput"><span class="keyword">unsigned</span></code> representing the HTTP status-code. 83 </li> 84<li class="listitem"> 85 <code class="computeroutput"><span class="identifier">m</span></code> is a value of type 86 <a class="link" href="../ref/boost__beast__http__verb.html" title="http::verb"><code class="computeroutput"><span class="identifier">verb</span></code></a>. 87 </li> 88</ul></div> 89<div class="table"> 90<a name="beast.concepts.FieldsWriter.valid_expressions"></a><p class="title"><b>Table 1.42. Valid expressions</b></p> 91<div class="table-contents"><table class="table" summary="Valid expressions"> 92<colgroup> 93<col> 94<col> 95<col> 96</colgroup> 97<thead><tr> 98<th> 99 <p> 100 expression 101 </p> 102 </th> 103<th> 104 <p> 105 type 106 </p> 107 </th> 108<th> 109 <p> 110 semantics, pre/post-conditions 111 </p> 112 </th> 113</tr></thead> 114<tbody> 115<tr> 116<td> 117 <p> 118 <code class="computeroutput"><span class="identifier">W</span><span class="special">::</span><span class="identifier">const_buffers_type</span></code> 119 </p> 120 </td> 121<td> 122 </td> 123<td> 124 <p> 125 A type which meets the requirements of <a href="../../../../../../doc/html/boost_asio/reference/ConstBufferSequence.html" target="_top"><span class="emphasis"><em>ConstBufferSequence</em></span></a>. 126 This is the type of buffer returned by <code class="computeroutput"><span class="identifier">W</span><span class="special">::</span><span class="identifier">get</span></code>. 127 </p> 128 </td> 129</tr> 130<tr> 131<td> 132 <p> 133 <code class="computeroutput"><span class="identifier">W</span><span class="special">{</span><span class="identifier">f</span><span class="special">,</span><span class="identifier">v</span><span class="special">,</span><span class="identifier">m</span><span class="special">}</span></code> 134 </p> 135 </td> 136<td> 137 </td> 138<td> 139 <p> 140 The implementation calls this constructor to indicate that the 141 fields being serialized form part of an HTTP request. The lifetime 142 of <code class="computeroutput"><span class="identifier">f</span></code> is guaranteed 143 to end no earlier than after the <code class="computeroutput"><span class="identifier">W</span></code> 144 is destroyed. 145 </p> 146 </td> 147</tr> 148<tr> 149<td> 150 <p> 151 <code class="computeroutput"><span class="identifier">W</span><span class="special">{</span><span class="identifier">f</span><span class="special">,</span><span class="identifier">v</span><span class="special">,</span><span class="identifier">c</span><span class="special">}</span></code> 152 </p> 153 </td> 154<td> 155 </td> 156<td> 157 <p> 158 The implementation calls this constructor to indicate that the 159 fields being serialized form part of an HTTP response. The lifetime 160 of <code class="computeroutput"><span class="identifier">f</span></code> is guaranteed 161 to end no earlier than after the <code class="computeroutput"><span class="identifier">W</span></code> 162 is destroyed. 163 </p> 164 </td> 165</tr> 166<tr> 167<td> 168 <p> 169 <code class="computeroutput"><span class="identifier">W</span><span class="special">{</span><span class="identifier">f</span><span class="special">}</span></code> 170 </p> 171 </td> 172<td> 173 </td> 174<td> 175 <p> 176 The implementation calls this constructor to indicate that the 177 fields being serialized form part of a chunked encoding final-chunk 178 trailer. The lifetime of <code class="computeroutput"><span class="identifier">f</span></code> 179 is guaranteed to end no earlier than after the <code class="computeroutput"><span class="identifier">W</span></code> 180 is destroyed. 181 </p> 182 </td> 183</tr> 184<tr> 185<td> 186 <p> 187 <code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span></code> 188 </p> 189 </td> 190<td> 191 <p> 192 <code class="computeroutput"><span class="identifier">W</span><span class="special">::</span><span class="identifier">const_buffers_type</span></code> 193 </p> 194 </td> 195<td> 196 <p> 197 Called once after construction, this function returns a constant 198 buffer sequence containing the serialized representation of the 199 HTTP request or response including the final carriage return linefeed 200 sequence (<code class="computeroutput"><span class="string">"\r\n"</span></code>). 201 </p> 202 <p> 203 Copies may be made of the returned sequence, but the underlying 204 memory is still owned by the writer. The implementation will destroy 205 all copies of the buffer sequence before destroying <code class="computeroutput"><span class="identifier">a</span></code>. 206 </p> 207 </td> 208</tr> 209</tbody> 210</table></div> 211</div> 212<br class="table-break"><h5> 213<a name="beast.concepts.FieldsWriter.h2"></a> 214 <span class="phrase"><a name="beast.concepts.FieldsWriter.exemplar"></a></span><a class="link" href="FieldsWriter.html#beast.concepts.FieldsWriter.exemplar">Exemplar</a> 215 </h5> 216<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">FieldsWriter</span> 217<span class="special">{</span> 218 <span class="comment">// The type of buffers returned by `get`</span> 219 <span class="keyword">struct</span> <span class="identifier">const_buffers_type</span><span class="special">;</span> 220 221 <span class="comment">// Constructor for requests</span> 222 <span class="identifier">FieldsWriter</span><span class="special">(</span><span class="identifier">Fields</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">f</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">version</span><span class="special">,</span> <span class="identifier">verb</span> <span class="identifier">method</span><span class="special">);</span> 223 224 <span class="comment">// Constructor for responses</span> 225 <span class="identifier">FieldsWriter</span><span class="special">(</span><span class="identifier">Fields</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">f</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">version</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">status</span><span class="special">);</span> 226 227 <span class="comment">// Returns the serialized header buffers</span> 228 <span class="identifier">const_buffers_type</span> 229 <span class="identifier">get</span><span class="special">();</span> 230<span class="special">};</span> 231</pre> 232<h5> 233<a name="beast.concepts.FieldsWriter.h3"></a> 234 <span class="phrase"><a name="beast.concepts.FieldsWriter.models"></a></span><a class="link" href="FieldsWriter.html#beast.concepts.FieldsWriter.models">Models</a> 235 </h5> 236<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 237 <a class="link" href="../ref/boost__beast__http__basic_fields/writer.html" title="http::basic_fields::writer"><code class="computeroutput"><span class="identifier">basic_fields</span><span class="special">::</span><span class="identifier">writer</span></code></a> 238 </li></ul></div> 239</div> 240<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 241<td align="left"></td> 242<td align="right"><div class="copyright-footer">Copyright © 2016-2019 Vinnie 243 Falco<p> 244 Distributed under the Boost Software License, Version 1.0. (See accompanying 245 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>) 246 </p> 247</div></td> 248</tr></table> 249<hr> 250<div class="spirit-nav"> 251<a accesskey="p" href="Fields.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="File.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 252</div> 253</body> 254</html> 255