write.hpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #ifndef BOOST_BEAST_HTTP_WRITE_HPP
  10. #define BOOST_BEAST_HTTP_WRITE_HPP
  11. #include <boost/beast/core/detail/config.hpp>
  12. #include <boost/beast/http/message.hpp>
  13. #include <boost/beast/http/serializer.hpp>
  14. #include <boost/beast/http/type_traits.hpp>
  15. #include <boost/beast/http/detail/chunk_encode.hpp>
  16. #include <boost/beast/core/error.hpp>
  17. #include <boost/beast/core/stream_traits.hpp>
  18. #include <boost/asio/async_result.hpp>
  19. #include <iosfwd>
  20. #include <limits>
  21. #include <memory>
  22. #include <type_traits>
  23. #include <utility>
  24. namespace boost {
  25. namespace beast {
  26. namespace http {
  27. /** Write part of a message to a stream using a serializer.
  28. This function is used to write part of a message to a stream using
  29. a caller-provided HTTP/1 serializer. The call will block until one
  30. of the following conditions is true:
  31. @li One or more bytes have been transferred.
  32. @li The function @ref serializer::is_done returns `true`
  33. @li An error occurs on the stream.
  34. This operation is implemented in terms of one or more calls
  35. to the stream's `write_some` function.
  36. The amount of data actually transferred is controlled by the behavior
  37. of the underlying stream, subject to the buffer size limit of the
  38. serializer obtained or set through a call to @ref serializer::limit.
  39. Setting a limit and performing bounded work helps applications set
  40. reasonable timeouts. It also allows application-level flow control
  41. to function correctly. For example when using a TCP/IP based
  42. stream.
  43. @param stream The stream to which the data is to be written.
  44. The type must support the <em>SyncWriteStream</em> concept.
  45. @param sr The serializer to use.
  46. @return The number of bytes written to the stream.
  47. @throws system_error Thrown on failure.
  48. @see serializer
  49. */
  50. template<
  51. class SyncWriteStream,
  52. bool isRequest, class Body, class Fields>
  53. std::size_t
  54. write_some(
  55. SyncWriteStream& stream,
  56. serializer<isRequest, Body, Fields>& sr);
  57. /** Write part of a message to a stream using a serializer.
  58. This function is used to write part of a message to a stream using
  59. a caller-provided HTTP/1 serializer. The call will block until one
  60. of the following conditions is true:
  61. @li One or more bytes have been transferred.
  62. @li The function @ref serializer::is_done returns `true`
  63. @li An error occurs on the stream.
  64. This operation is implemented in terms of one or more calls
  65. to the stream's `write_some` function.
  66. The amount of data actually transferred is controlled by the behavior
  67. of the underlying stream, subject to the buffer size limit of the
  68. serializer obtained or set through a call to @ref serializer::limit.
  69. Setting a limit and performing bounded work helps applications set
  70. reasonable timeouts. It also allows application-level flow control
  71. to function correctly. For example when using a TCP/IP based
  72. stream.
  73. @param stream The stream to which the data is to be written.
  74. The type must support the <em>SyncWriteStream</em> concept.
  75. @param sr The serializer to use.
  76. @param ec Set to indicate what error occurred, if any.
  77. @return The number of bytes written to the stream.
  78. @see async_write_some, serializer
  79. */
  80. template<
  81. class SyncWriteStream,
  82. bool isRequest, class Body, class Fields>
  83. std::size_t
  84. write_some(
  85. SyncWriteStream& stream,
  86. serializer<isRequest, Body, Fields>& sr,
  87. error_code& ec);
  88. /** Write part of a message to a stream asynchronously using a serializer.
  89. This function is used to write part of a message to a stream
  90. asynchronously using a caller-provided HTTP/1 serializer. The function
  91. call always returns immediately. The asynchronous operation will continue
  92. until one of the following conditions is true:
  93. @li One or more bytes have been transferred.
  94. @li The function @ref serializer::is_done returns `true`
  95. @li An error occurs on the stream.
  96. This operation is implemented in terms of zero or more calls to the stream's
  97. `async_write_some` function, and is known as a <em>composed operation</em>.
  98. The program must ensure that the stream performs no other writes
  99. until this operation completes.
  100. The amount of data actually transferred is controlled by the behavior
  101. of the underlying stream, subject to the buffer size limit of the
  102. serializer obtained or set through a call to @ref serializer::limit.
  103. Setting a limit and performing bounded work helps applications set
  104. reasonable timeouts. It also allows application-level flow control
  105. to function correctly. For example when using a TCP/IP based
  106. stream.
  107. @param stream The stream to which the data is to be written.
  108. The type must support the <em>AsyncWriteStream</em> concept.
  109. @param sr The serializer to use.
  110. The object must remain valid at least until the
  111. handler is called; ownership is not transferred.
  112. @param handler The completion handler to invoke when the operation
  113. completes. The implementation takes ownership of the handler by
  114. performing a decay-copy. The equivalent function signature of
  115. the handler must be:
  116. @code
  117. void handler(
  118. error_code const& error, // result of operation
  119. std::size_t bytes_transferred // the number of bytes written to the stream
  120. );
  121. @endcode
  122. Regardless of whether the asynchronous operation completes
  123. immediately or not, the handler will not be invoked from within
  124. this function. Invocation of the handler will be performed in a
  125. manner equivalent to using `net::post`.
  126. @see serializer
  127. */
  128. template<
  129. class AsyncWriteStream,
  130. bool isRequest, class Body, class Fields,
  131. BOOST_BEAST_ASYNC_TPARAM2 WriteHandler =
  132. net::default_completion_token_t<
  133. executor_type<AsyncWriteStream>>>
  134. BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
  135. async_write_some(
  136. AsyncWriteStream& stream,
  137. serializer<isRequest, Body, Fields>& sr,
  138. WriteHandler&& handler =
  139. net::default_completion_token_t<
  140. executor_type<AsyncWriteStream>>{});
  141. //------------------------------------------------------------------------------
  142. /** Write a header to a stream using a serializer.
  143. This function is used to write a header to a stream using a
  144. caller-provided HTTP/1 serializer. The call will block until one
  145. of the following conditions is true:
  146. @li The function @ref serializer::is_header_done returns `true`
  147. @li An error occurs.
  148. This operation is implemented in terms of one or more calls
  149. to the stream's `write_some` function.
  150. @param stream The stream to which the data is to be written.
  151. The type must support the <em>SyncWriteStream</em> concept.
  152. @param sr The serializer to use.
  153. @return The number of bytes written to the stream.
  154. @throws system_error Thrown on failure.
  155. @note The implementation will call @ref serializer::split with
  156. the value `true` on the serializer passed in.
  157. @see serializer
  158. */
  159. template<
  160. class SyncWriteStream,
  161. bool isRequest, class Body, class Fields>
  162. std::size_t
  163. write_header(
  164. SyncWriteStream& stream,
  165. serializer<isRequest, Body, Fields>& sr);
  166. /** Write a header to a stream using a serializer.
  167. This function is used to write a header to a stream using a
  168. caller-provided HTTP/1 serializer. The call will block until one
  169. of the following conditions is true:
  170. @li The function @ref serializer::is_header_done returns `true`
  171. @li An error occurs.
  172. This operation is implemented in terms of one or more calls
  173. to the stream's `write_some` function.
  174. @param stream The stream to which the data is to be written.
  175. The type must support the <em>SyncWriteStream</em> concept.
  176. @param sr The serializer to use.
  177. @param ec Set to indicate what error occurred, if any.
  178. @return The number of bytes written to the stream.
  179. @note The implementation will call @ref serializer::split with
  180. the value `true` on the serializer passed in.
  181. @see serializer
  182. */
  183. template<
  184. class SyncWriteStream,
  185. bool isRequest, class Body, class Fields>
  186. std::size_t
  187. write_header(
  188. SyncWriteStream& stream,
  189. serializer<isRequest, Body, Fields>& sr,
  190. error_code& ec);
  191. /** Write a header to a stream asynchronously using a serializer.
  192. This function is used to write a header to a stream asynchronously
  193. using a caller-provided HTTP/1 serializer. The function call always
  194. returns immediately. The asynchronous operation will continue until
  195. one of the following conditions is true:
  196. @li The function @ref serializer::is_header_done returns `true`
  197. @li An error occurs.
  198. This operation is implemented in terms of zero or more calls to the stream's
  199. `async_write_some` function, and is known as a <em>composed operation</em>.
  200. The program must ensure that the stream performs no other writes
  201. until this operation completes.
  202. @param stream The stream to which the data is to be written.
  203. The type must support the <em>AsyncWriteStream</em> concept.
  204. @param sr The serializer to use.
  205. The object must remain valid at least until the
  206. handler is called; ownership is not transferred.
  207. @param handler The completion handler to invoke when the operation
  208. completes. The implementation takes ownership of the handler by
  209. performing a decay-copy. The equivalent function signature of
  210. the handler must be:
  211. @code
  212. void handler(
  213. error_code const& error, // result of operation
  214. std::size_t bytes_transferred // the number of bytes written to the stream
  215. );
  216. @endcode
  217. Regardless of whether the asynchronous operation completes
  218. immediately or not, the handler will not be invoked from within
  219. this function. Invocation of the handler will be performed in a
  220. manner equivalent to using `net::post`.
  221. @note The implementation will call @ref serializer::split with
  222. the value `true` on the serializer passed in.
  223. @see serializer
  224. */
  225. template<
  226. class AsyncWriteStream,
  227. bool isRequest, class Body, class Fields,
  228. BOOST_BEAST_ASYNC_TPARAM2 WriteHandler =
  229. net::default_completion_token_t<
  230. executor_type<AsyncWriteStream>>>
  231. BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
  232. async_write_header(
  233. AsyncWriteStream& stream,
  234. serializer<isRequest, Body, Fields>& sr,
  235. WriteHandler&& handler =
  236. net::default_completion_token_t<
  237. executor_type<AsyncWriteStream>>{});
  238. //------------------------------------------------------------------------------
  239. /** Write a complete message to a stream using a serializer.
  240. This function is used to write a complete message to a stream using
  241. a caller-provided HTTP/1 serializer. The call will block until one
  242. of the following conditions is true:
  243. @li The function @ref serializer::is_done returns `true`
  244. @li An error occurs.
  245. This operation is implemented in terms of one or more calls
  246. to the stream's `write_some` function.
  247. @param stream The stream to which the data is to be written.
  248. The type must support the <em>SyncWriteStream</em> concept.
  249. @param sr The serializer to use.
  250. @return The number of bytes written to the stream.
  251. @throws system_error Thrown on failure.
  252. @see serializer
  253. */
  254. template<
  255. class SyncWriteStream,
  256. bool isRequest, class Body, class Fields>
  257. std::size_t
  258. write(
  259. SyncWriteStream& stream,
  260. serializer<isRequest, Body, Fields>& sr);
  261. /** Write a complete message to a stream using a serializer.
  262. This function is used to write a complete message to a stream using
  263. a caller-provided HTTP/1 serializer. The call will block until one
  264. of the following conditions is true:
  265. @li The function @ref serializer::is_done returns `true`
  266. @li An error occurs.
  267. This operation is implemented in terms of one or more calls
  268. to the stream's `write_some` function.
  269. @param stream The stream to which the data is to be written.
  270. The type must support the <em>SyncWriteStream</em> concept.
  271. @param sr The serializer to use.
  272. @param ec Set to the error, if any occurred.
  273. @return The number of bytes written to the stream.
  274. @see serializer
  275. */
  276. template<
  277. class SyncWriteStream,
  278. bool isRequest, class Body, class Fields>
  279. std::size_t
  280. write(
  281. SyncWriteStream& stream,
  282. serializer<isRequest, Body, Fields>& sr,
  283. error_code& ec);
  284. /** Write a complete message to a stream asynchronously using a serializer.
  285. This function is used to write a complete message to a stream
  286. asynchronously using a caller-provided HTTP/1 serializer. The
  287. function call always returns immediately. The asynchronous
  288. operation will continue until one of the following conditions is true:
  289. @li The function @ref serializer::is_done returns `true`
  290. @li An error occurs.
  291. This operation is implemented in terms of zero or more calls to the stream's
  292. `async_write_some` function, and is known as a <em>composed operation</em>.
  293. The program must ensure that the stream performs no other writes
  294. until this operation completes.
  295. @param stream The stream to which the data is to be written.
  296. The type must support the <em>AsyncWriteStream</em> concept.
  297. @param sr The serializer to use.
  298. The object must remain valid at least until the
  299. handler is called; ownership is not transferred.
  300. @param handler The completion handler to invoke when the operation
  301. completes. The implementation takes ownership of the handler by
  302. performing a decay-copy. The equivalent function signature of
  303. the handler must be:
  304. @code
  305. void handler(
  306. error_code const& error, // result of operation
  307. std::size_t bytes_transferred // the number of bytes written to the stream
  308. );
  309. @endcode
  310. Regardless of whether the asynchronous operation completes
  311. immediately or not, the handler will not be invoked from within
  312. this function. Invocation of the handler will be performed in a
  313. manner equivalent to using `net::post`.
  314. @see serializer
  315. */
  316. template<
  317. class AsyncWriteStream,
  318. bool isRequest, class Body, class Fields,
  319. BOOST_BEAST_ASYNC_TPARAM2 WriteHandler =
  320. net::default_completion_token_t<
  321. executor_type<AsyncWriteStream>>>
  322. BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
  323. async_write(
  324. AsyncWriteStream& stream,
  325. serializer<isRequest, Body, Fields>& sr,
  326. WriteHandler&& handler =
  327. net::default_completion_token_t<
  328. executor_type<AsyncWriteStream>>{});
  329. //------------------------------------------------------------------------------
  330. /** Write a complete message to a stream.
  331. This function is used to write a complete message to a stream using
  332. HTTP/1. The call will block until one of the following conditions is true:
  333. @li The entire message is written.
  334. @li An error occurs.
  335. This operation is implemented in terms of one or more calls to the stream's
  336. `write_some` function. The algorithm will use a temporary @ref serializer
  337. with an empty chunk decorator to produce buffers.
  338. @note This function only participates in overload resolution
  339. if @ref is_mutable_body_writer for <em>Body</em> returns `true`.
  340. @param stream The stream to which the data is to be written.
  341. The type must support the <em>SyncWriteStream</em> concept.
  342. @param msg The message to write.
  343. @return The number of bytes written to the stream.
  344. @throws system_error Thrown on failure.
  345. @see message
  346. */
  347. template<
  348. class SyncWriteStream,
  349. bool isRequest, class Body, class Fields>
  350. #if BOOST_BEAST_DOXYGEN
  351. std::size_t
  352. #else
  353. typename std::enable_if<
  354. is_mutable_body_writer<Body>::value,
  355. std::size_t>::type
  356. #endif
  357. write(
  358. SyncWriteStream& stream,
  359. message<isRequest, Body, Fields>& msg);
  360. /** Write a complete message to a stream.
  361. This function is used to write a complete message to a stream using
  362. HTTP/1. The call will block until one of the following conditions is true:
  363. @li The entire message is written.
  364. @li An error occurs.
  365. This operation is implemented in terms of one or more calls to the stream's
  366. `write_some` function. The algorithm will use a temporary @ref serializer
  367. with an empty chunk decorator to produce buffers.
  368. @note This function only participates in overload resolution
  369. if @ref is_mutable_body_writer for <em>Body</em> returns `false`.
  370. @param stream The stream to which the data is to be written.
  371. The type must support the <em>SyncWriteStream</em> concept.
  372. @param msg The message to write.
  373. @return The number of bytes written to the stream.
  374. @throws system_error Thrown on failure.
  375. @see message
  376. */
  377. template<
  378. class SyncWriteStream,
  379. bool isRequest, class Body, class Fields>
  380. #if BOOST_BEAST_DOXYGEN
  381. std::size_t
  382. #else
  383. typename std::enable_if<
  384. ! is_mutable_body_writer<Body>::value,
  385. std::size_t>::type
  386. #endif
  387. write(
  388. SyncWriteStream& stream,
  389. message<isRequest, Body, Fields> const& msg);
  390. /** Write a complete message to a stream.
  391. This function is used to write a complete message to a stream using
  392. HTTP/1. The call will block until one of the following conditions is true:
  393. @li The entire message is written.
  394. @li An error occurs.
  395. This operation is implemented in terms of one or more calls to the stream's
  396. `write_some` function. The algorithm will use a temporary @ref serializer
  397. with an empty chunk decorator to produce buffers.
  398. @note This function only participates in overload resolution
  399. if @ref is_mutable_body_writer for <em>Body</em> returns `true`.
  400. @param stream The stream to which the data is to be written.
  401. The type must support the <em>SyncWriteStream</em> concept.
  402. @param msg The message to write.
  403. @param ec Set to the error, if any occurred.
  404. @return The number of bytes written to the stream.
  405. @see message
  406. */
  407. template<
  408. class SyncWriteStream,
  409. bool isRequest, class Body, class Fields>
  410. #if BOOST_BEAST_DOXYGEN
  411. std::size_t
  412. #else
  413. typename std::enable_if<
  414. is_mutable_body_writer<Body>::value,
  415. std::size_t>::type
  416. #endif
  417. write(
  418. SyncWriteStream& stream,
  419. message<isRequest, Body, Fields>& msg,
  420. error_code& ec);
  421. /** Write a complete message to a stream.
  422. This function is used to write a complete message to a stream using
  423. HTTP/1. The call will block until one of the following conditions is true:
  424. @li The entire message is written.
  425. @li An error occurs.
  426. This operation is implemented in terms of one or more calls to the stream's
  427. `write_some` function. The algorithm will use a temporary @ref serializer
  428. with an empty chunk decorator to produce buffers.
  429. @note This function only participates in overload resolution
  430. if @ref is_mutable_body_writer for <em>Body</em> returns `false`.
  431. @param stream The stream to which the data is to be written.
  432. The type must support the <em>SyncWriteStream</em> concept.
  433. @param msg The message to write.
  434. @param ec Set to the error, if any occurred.
  435. @return The number of bytes written to the stream.
  436. @see message
  437. */
  438. template<
  439. class SyncWriteStream,
  440. bool isRequest, class Body, class Fields>
  441. #if BOOST_BEAST_DOXYGEN
  442. std::size_t
  443. #else
  444. typename std::enable_if<
  445. ! is_mutable_body_writer<Body>::value,
  446. std::size_t>::type
  447. #endif
  448. write(
  449. SyncWriteStream& stream,
  450. message<isRequest, Body, Fields> const& msg,
  451. error_code& ec);
  452. /** Write a complete message to a stream asynchronously.
  453. This function is used to write a complete message to a stream asynchronously
  454. using HTTP/1. The function call always returns immediately. The asynchronous
  455. operation will continue until one of the following conditions is true:
  456. @li The entire message is written.
  457. @li An error occurs.
  458. This operation is implemented in terms of zero or more calls to the stream's
  459. `async_write_some` function, and is known as a <em>composed operation</em>.
  460. The program must ensure that the stream performs no other writes
  461. until this operation completes. The algorithm will use a temporary
  462. @ref serializer with an empty chunk decorator to produce buffers.
  463. @note This function only participates in overload resolution
  464. if @ref is_mutable_body_writer for <em>Body</em> returns `true`.
  465. @param stream The stream to which the data is to be written.
  466. The type must support the <em>AsyncWriteStream</em> concept.
  467. @param msg The message to write.
  468. The object must remain valid at least until the
  469. handler is called; ownership is not transferred.
  470. @param handler The completion handler to invoke when the operation
  471. completes. The implementation takes ownership of the handler by
  472. performing a decay-copy. The equivalent function signature of
  473. the handler must be:
  474. @code
  475. void handler(
  476. error_code const& error, // result of operation
  477. std::size_t bytes_transferred // the number of bytes written to the stream
  478. );
  479. @endcode
  480. Regardless of whether the asynchronous operation completes
  481. immediately or not, the handler will not be invoked from within
  482. this function. Invocation of the handler will be performed in a
  483. manner equivalent to using `net::post`.
  484. @see message
  485. */
  486. template<
  487. class AsyncWriteStream,
  488. bool isRequest, class Body, class Fields,
  489. BOOST_BEAST_ASYNC_TPARAM2 WriteHandler =
  490. net::default_completion_token_t<
  491. executor_type<AsyncWriteStream>>>
  492. BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
  493. async_write(
  494. AsyncWriteStream& stream,
  495. message<isRequest, Body, Fields>& msg,
  496. WriteHandler&& handler =
  497. net::default_completion_token_t<
  498. executor_type<AsyncWriteStream>>{}
  499. #ifndef BOOST_BEAST_DOXYGEN
  500. , typename std::enable_if<
  501. is_mutable_body_writer<Body>::value>::type* = 0
  502. #endif
  503. );
  504. /** Write a complete message to a stream asynchronously.
  505. This function is used to write a complete message to a stream asynchronously
  506. using HTTP/1. The function call always returns immediately. The asynchronous
  507. operation will continue until one of the following conditions is true:
  508. @li The entire message is written.
  509. @li An error occurs.
  510. This operation is implemented in terms of zero or more calls to the stream's
  511. `async_write_some` function, and is known as a <em>composed operation</em>.
  512. The program must ensure that the stream performs no other writes
  513. until this operation completes. The algorithm will use a temporary
  514. @ref serializer with an empty chunk decorator to produce buffers.
  515. @note This function only participates in overload resolution
  516. if @ref is_mutable_body_writer for <em>Body</em> returns `false`.
  517. @param stream The stream to which the data is to be written.
  518. The type must support the <em>AsyncWriteStream</em> concept.
  519. @param msg The message to write.
  520. The object must remain valid at least until the
  521. handler is called; ownership is not transferred.
  522. @param handler The completion handler to invoke when the operation
  523. completes. The implementation takes ownership of the handler by
  524. performing a decay-copy. The equivalent function signature of
  525. the handler must be:
  526. @code
  527. void handler(
  528. error_code const& error, // result of operation
  529. std::size_t bytes_transferred // the number of bytes written to the stream
  530. );
  531. @endcode
  532. Regardless of whether the asynchronous operation completes
  533. immediately or not, the handler will not be invoked from within
  534. this function. Invocation of the handler will be performed in a
  535. manner equivalent to using `net::post`.
  536. @see message
  537. */
  538. template<
  539. class AsyncWriteStream,
  540. bool isRequest, class Body, class Fields,
  541. BOOST_BEAST_ASYNC_TPARAM2 WriteHandler =
  542. net::default_completion_token_t<
  543. executor_type<AsyncWriteStream>>>
  544. BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
  545. async_write(
  546. AsyncWriteStream& stream,
  547. message<isRequest, Body, Fields> const& msg,
  548. WriteHandler&& handler =
  549. net::default_completion_token_t<
  550. executor_type<AsyncWriteStream>>{}
  551. #ifndef BOOST_BEAST_DOXYGEN
  552. , typename std::enable_if<
  553. ! is_mutable_body_writer<Body>::value>::type* = 0
  554. #endif
  555. );
  556. //------------------------------------------------------------------------------
  557. /** Serialize an HTTP/1 header to a `std::ostream`.
  558. The function converts the header to its HTTP/1 serialized
  559. representation and stores the result in the output stream.
  560. @param os The output stream to write to.
  561. @param msg The message fields to write.
  562. */
  563. template<bool isRequest, class Fields>
  564. std::ostream&
  565. operator<<(std::ostream& os,
  566. header<isRequest, Fields> const& msg);
  567. /** Serialize an HTTP/1 message to a `std::ostream`.
  568. The function converts the message to its HTTP/1 serialized
  569. representation and stores the result in the output stream.
  570. The implementation will automatically perform chunk encoding if
  571. the contents of the message indicate that chunk encoding is required.
  572. @param os The output stream to write to.
  573. @param msg The message to write.
  574. */
  575. template<bool isRequest, class Body, class Fields>
  576. std::ostream&
  577. operator<<(std::ostream& os,
  578. message<isRequest, Body, Fields> const& msg);
  579. } // http
  580. } // beast
  581. } // boost
  582. #include <boost/beast/http/impl/write.hpp>
  583. #endif