Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:32

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #ifndef BOOST_BEAST_HTTP_WRITE_HPP
0011 #define BOOST_BEAST_HTTP_WRITE_HPP
0012 
0013 #include <boost/beast/core/detail/config.hpp>
0014 #include <boost/beast/http/message.hpp>
0015 #include <boost/beast/http/serializer.hpp>
0016 #include <boost/beast/http/type_traits.hpp>
0017 #include <boost/beast/http/detail/chunk_encode.hpp>
0018 #include <boost/beast/core/error.hpp>
0019 #include <boost/beast/core/stream_traits.hpp>
0020 #include <boost/asio/async_result.hpp>
0021 #include <iosfwd>
0022 #include <limits>
0023 #include <memory>
0024 #include <type_traits>
0025 #include <utility>
0026 
0027 namespace boost {
0028 namespace beast {
0029 namespace http {
0030 
0031 /** Write part of a message to a stream using a serializer.
0032 
0033     This function is used to write part of a message to a stream using
0034     a caller-provided HTTP/1 serializer. The call will block until one
0035     of the following conditions is true:
0036         
0037     @li One or more bytes have been transferred.
0038 
0039     @li The function @ref serializer::is_done returns `true`
0040 
0041     @li An error occurs on the stream.
0042 
0043     This operation is implemented in terms of one or more calls
0044     to the stream's `write_some` function.
0045 
0046     The amount of data actually transferred is controlled by the behavior
0047     of the underlying stream, subject to the buffer size limit of the
0048     serializer obtained or set through a call to @ref serializer::limit.
0049     Setting a limit and performing bounded work helps applications set
0050     reasonable timeouts. It also allows application-level flow control
0051     to function correctly. For example when using a TCP/IP based
0052     stream.
0053 
0054     @param stream The stream to which the data is to be written.
0055     The type must support the <em>SyncWriteStream</em> concept.
0056 
0057     @param sr The serializer to use.
0058 
0059     @return The number of bytes written to the stream.
0060 
0061     @throws system_error Thrown on failure.
0062 
0063     @see serializer
0064 */
0065 template<
0066     class SyncWriteStream,
0067     bool isRequest, class Body, class Fields>
0068 std::size_t
0069 write_some(
0070     SyncWriteStream& stream,
0071     serializer<isRequest, Body, Fields>& sr);
0072 
0073 /** Write part of a message to a stream using a serializer.
0074 
0075     This function is used to write part of a message to a stream using
0076     a caller-provided HTTP/1 serializer. The call will block until one
0077     of the following conditions is true:
0078         
0079     @li One or more bytes have been transferred.
0080 
0081     @li The function @ref serializer::is_done returns `true`
0082 
0083     @li An error occurs on the stream.
0084 
0085     This operation is implemented in terms of one or more calls
0086     to the stream's `write_some` function.
0087 
0088     The amount of data actually transferred is controlled by the behavior
0089     of the underlying stream, subject to the buffer size limit of the
0090     serializer obtained or set through a call to @ref serializer::limit.
0091     Setting a limit and performing bounded work helps applications set
0092     reasonable timeouts. It also allows application-level flow control
0093     to function correctly. For example when using a TCP/IP based
0094     stream.
0095     
0096     @param stream The stream to which the data is to be written.
0097     The type must support the <em>SyncWriteStream</em> concept.
0098 
0099     @param sr The serializer to use.
0100 
0101     @param ec Set to indicate what error occurred, if any.
0102 
0103     @return The number of bytes written to the stream.
0104 
0105     @see async_write_some, serializer
0106 */
0107 template<
0108     class SyncWriteStream,
0109     bool isRequest, class Body, class Fields>
0110 std::size_t
0111 write_some(
0112     SyncWriteStream& stream,
0113     serializer<isRequest, Body, Fields>& sr,
0114     error_code& ec);
0115 
0116 /** Write part of a message to a stream asynchronously using a serializer.
0117 
0118     This function is used to write part of a message to a stream
0119     asynchronously using a caller-provided HTTP/1 serializer. The function
0120     call always returns immediately. The asynchronous operation will continue
0121     until one of the following conditions is true:
0122 
0123     @li One or more bytes have been transferred.
0124 
0125     @li The function @ref serializer::is_done returns `true`
0126 
0127     @li An error occurs on the stream.
0128 
0129     This operation is implemented in terms of zero or more calls to the stream's
0130     `async_write_some` function, and is known as a <em>composed operation</em>.
0131     The program must ensure that the stream performs no other writes
0132     until this operation completes.
0133 
0134     The amount of data actually transferred is controlled by the behavior
0135     of the underlying stream, subject to the buffer size limit of the
0136     serializer obtained or set through a call to @ref serializer::limit.
0137     Setting a limit and performing bounded work helps applications set
0138     reasonable timeouts. It also allows application-level flow control
0139     to function correctly. For example when using a TCP/IP based
0140     stream.
0141     
0142     @param stream The stream to which the data is to be written.
0143     The type must support the <em>AsyncWriteStream</em> concept.
0144 
0145     @param sr The serializer to use.
0146     The object must remain valid at least until the
0147     handler is called; ownership is not transferred.
0148 
0149     @param handler The completion handler to invoke when the operation
0150     completes. The implementation takes ownership of the handler by
0151     performing a decay-copy. The equivalent function signature of
0152     the handler must be:
0153     @code
0154     void handler(
0155         error_code const& error,        // result of operation
0156         std::size_t bytes_transferred   // the number of bytes written to the stream
0157     );
0158     @endcode
0159     If the handler has an associated immediate executor,
0160     an immediate completion will be dispatched to it.
0161     Otherwise, the handler will not be invoked from within
0162     this function. Invocation of the handler will be performed in a
0163     manner equivalent to using `net::post`.
0164 
0165     @par Per-Operation Cancellation
0166 
0167     This asynchronous operation supports cancellation for the following
0168     net::cancellation_type values:
0169 
0170     @li @c net::cancellation_type::terminal
0171 
0172     if the `stream` also supports terminal cancellation.
0173 
0174     `terminal` cancellation leaves the stream in an undefined state,
0175     so that only closing it is guaranteed to succeed.
0176 
0177     @see serializer
0178 */
0179 template<
0180     class AsyncWriteStream,
0181     bool isRequest, class Body, class Fields,
0182     BOOST_BEAST_ASYNC_TPARAM2 WriteHandler =
0183         net::default_completion_token_t<
0184             executor_type<AsyncWriteStream>>>
0185 BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
0186 async_write_some(
0187     AsyncWriteStream& stream,
0188     serializer<isRequest, Body, Fields>& sr,
0189     WriteHandler&& handler =
0190         net::default_completion_token_t<
0191             executor_type<AsyncWriteStream>>{});
0192 
0193 //------------------------------------------------------------------------------
0194 
0195 /** Write a header to a stream using a serializer.
0196 
0197     This function is used to write a header to a stream using a
0198     caller-provided HTTP/1 serializer. The call will block until one
0199     of the following conditions is true:
0200 
0201     @li The function @ref serializer::is_header_done returns `true`
0202 
0203     @li An error occurs.
0204 
0205     This operation is implemented in terms of one or more calls
0206     to the stream's `write_some` function.
0207 
0208     @param stream The stream to which the data is to be written.
0209     The type must support the <em>SyncWriteStream</em> concept.
0210 
0211     @param sr The serializer to use.
0212 
0213     @return The number of bytes written to the stream.
0214 
0215     @throws system_error Thrown on failure.
0216 
0217     @note The implementation will call @ref serializer::split with
0218     the value `true` on the serializer passed in.
0219 
0220     @see serializer
0221 */
0222 template<
0223     class SyncWriteStream,
0224     bool isRequest, class Body, class Fields>
0225 std::size_t
0226 write_header(
0227     SyncWriteStream& stream,
0228     serializer<isRequest, Body, Fields>& sr);
0229 
0230 /** Write a header to a stream using a serializer.
0231 
0232     This function is used to write a header to a stream using a
0233     caller-provided HTTP/1 serializer. The call will block until one
0234     of the following conditions is true:
0235 
0236     @li The function @ref serializer::is_header_done returns `true`
0237 
0238     @li An error occurs.
0239 
0240     This operation is implemented in terms of one or more calls
0241     to the stream's `write_some` function.
0242 
0243     @param stream The stream to which the data is to be written.
0244     The type must support the <em>SyncWriteStream</em> concept.
0245 
0246     @param sr The serializer to use.
0247 
0248     @param ec Set to indicate what error occurred, if any.
0249 
0250     @return The number of bytes written to the stream.
0251 
0252     @note The implementation will call @ref serializer::split with
0253     the value `true` on the serializer passed in.
0254 
0255     @see serializer
0256 */
0257 template<
0258     class SyncWriteStream,
0259     bool isRequest, class Body, class Fields>
0260 std::size_t
0261 write_header(
0262     SyncWriteStream& stream,
0263     serializer<isRequest, Body, Fields>& sr,
0264     error_code& ec);
0265 
0266 /** Write a header to a stream asynchronously using a serializer.
0267 
0268     This function is used to write a header to a stream asynchronously
0269     using a caller-provided HTTP/1 serializer. The function call always
0270     returns immediately. The asynchronous operation will continue until
0271     one of the following conditions is true:
0272 
0273     @li The function @ref serializer::is_header_done returns `true`
0274 
0275     @li An error occurs.
0276 
0277     This operation is implemented in terms of zero or more calls to the stream's
0278     `async_write_some` function, and is known as a <em>composed operation</em>.
0279     The program must ensure that the stream performs no other writes
0280     until this operation completes.
0281 
0282     @param stream The stream to which the data is to be written.
0283     The type must support the <em>AsyncWriteStream</em> concept.
0284 
0285     @param sr The serializer to use.
0286     The object must remain valid at least until the
0287     handler is called; ownership is not transferred.
0288 
0289     @param handler The completion handler to invoke when the operation
0290     completes. The implementation takes ownership of the handler by
0291     performing a decay-copy. The equivalent function signature of
0292     the handler must be:
0293     @code
0294     void handler(
0295         error_code const& error,        // result of operation
0296         std::size_t bytes_transferred   // the number of bytes written to the stream
0297     );
0298     @endcode
0299     If the handler has an associated immediate executor,
0300     an immediate completion will be dispatched to it.
0301     Otherwise, the handler will not be invoked from within
0302     this function. Invocation of the handler will be performed in a
0303     manner equivalent to using `net::post`.
0304 
0305     @note The implementation will call @ref serializer::split with
0306     the value `true` on the serializer passed in.
0307 
0308     @par Per-Operation Cancellation
0309 
0310     This asynchronous operation supports cancellation for the following
0311     net::cancellation_type values:
0312 
0313     @li @c net::cancellation_type::terminal
0314 
0315     if the `stream` also supports terminal cancellation.
0316 
0317     `terminal` cancellation leaves the stream in an undefined state,
0318     so that only closing it is guaranteed to succeed.
0319 
0320     @see serializer
0321 */
0322 template<
0323     class AsyncWriteStream,
0324     bool isRequest, class Body, class Fields,
0325     BOOST_BEAST_ASYNC_TPARAM2 WriteHandler =
0326         net::default_completion_token_t<
0327             executor_type<AsyncWriteStream>>>
0328 BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
0329 async_write_header(
0330     AsyncWriteStream& stream,
0331     serializer<isRequest, Body, Fields>& sr,
0332     WriteHandler&& handler =
0333         net::default_completion_token_t<
0334             executor_type<AsyncWriteStream>>{});
0335 
0336 //------------------------------------------------------------------------------
0337 
0338 /** Write a complete message to a stream using a serializer.
0339 
0340     This function is used to write a complete message to a stream using
0341     a caller-provided HTTP/1 serializer. The call will block until one
0342     of the following conditions is true:
0343 
0344     @li The function @ref serializer::is_done returns `true`
0345 
0346     @li An error occurs.
0347 
0348     This operation is implemented in terms of one or more calls
0349     to the stream's `write_some` function.
0350 
0351     @param stream The stream to which the data is to be written.
0352     The type must support the <em>SyncWriteStream</em> concept.
0353 
0354     @param sr The serializer to use.
0355 
0356     @return The number of bytes written to the stream.
0357 
0358     @throws system_error Thrown on failure.
0359 
0360     @see serializer
0361 */
0362 template<
0363     class SyncWriteStream,
0364     bool isRequest, class Body, class Fields>
0365 std::size_t
0366 write(
0367     SyncWriteStream& stream,
0368     serializer<isRequest, Body, Fields>& sr);
0369 
0370 /** Write a complete message to a stream using a serializer.
0371 
0372     This function is used to write a complete message to a stream using
0373     a caller-provided HTTP/1 serializer. The call will block until one
0374     of the following conditions is true:
0375 
0376     @li The function @ref serializer::is_done returns `true`
0377 
0378     @li An error occurs.
0379 
0380     This operation is implemented in terms of one or more calls
0381     to the stream's `write_some` function.
0382 
0383     @param stream The stream to which the data is to be written.
0384     The type must support the <em>SyncWriteStream</em> concept.
0385 
0386     @param sr The serializer to use.
0387 
0388     @param ec Set to the error, if any occurred.
0389 
0390     @return The number of bytes written to the stream.
0391 
0392     @see serializer
0393 */
0394 template<
0395     class SyncWriteStream,
0396     bool isRequest, class Body, class Fields>
0397 std::size_t
0398 write(
0399     SyncWriteStream& stream,
0400     serializer<isRequest, Body, Fields>& sr,
0401    error_code& ec);
0402 
0403 /** Write a complete message to a stream asynchronously using a serializer.
0404 
0405     This function is used to write a complete message to a stream
0406     asynchronously using a caller-provided HTTP/1 serializer. The
0407     function call always returns immediately. The asynchronous
0408     operation will continue until one of the following conditions is true:
0409 
0410     @li The function @ref serializer::is_done returns `true`
0411 
0412     @li An error occurs.
0413 
0414     This operation is implemented in terms of zero or more calls to the stream's
0415     `async_write_some` function, and is known as a <em>composed operation</em>.
0416     The program must ensure that the stream performs no other writes
0417     until this operation completes.
0418 
0419     @param stream The stream to which the data is to be written.
0420     The type must support the <em>AsyncWriteStream</em> concept.
0421 
0422     @param sr The serializer to use.
0423     The object must remain valid at least until the
0424     handler is called; ownership is not transferred.
0425 
0426     @param handler The completion handler to invoke when the operation
0427     completes. The implementation takes ownership of the handler by
0428     performing a decay-copy. The equivalent function signature of
0429     the handler must be:
0430     @code
0431     void handler(
0432         error_code const& error,        // result of operation
0433         std::size_t bytes_transferred   // the number of bytes written to the stream
0434     );
0435     @endcode
0436     If the handler has an associated immediate executor,
0437     an immediate completion will be dispatched to it.
0438     Otherwise, the handler will not be invoked from within
0439     this function. Invocation of the handler will be performed in a
0440     manner equivalent to using `net::post`.
0441 
0442     @par Per-Operation Cancellation
0443 
0444     This asynchronous operation supports cancellation for the following
0445     net::cancellation_type values:
0446 
0447     @li @c net::cancellation_type::terminal
0448 
0449     if the `stream` also supports terminal cancellation.
0450 
0451     `terminal` cancellation leaves the stream in an undefined state,
0452     so that only closing it is guaranteed to succeed.
0453 
0454     @see serializer
0455 */
0456 template<
0457     class AsyncWriteStream,
0458     bool isRequest, class Body, class Fields,
0459     BOOST_BEAST_ASYNC_TPARAM2 WriteHandler =
0460         net::default_completion_token_t<
0461             executor_type<AsyncWriteStream>>>
0462 BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
0463 async_write(
0464     AsyncWriteStream& stream,
0465     serializer<isRequest, Body, Fields>& sr,
0466     WriteHandler&& handler =
0467         net::default_completion_token_t<
0468             executor_type<AsyncWriteStream>>{});
0469 
0470 //------------------------------------------------------------------------------
0471 
0472 /** Write a complete message to a stream.
0473 
0474     This function is used to write a complete message to a stream using
0475     HTTP/1. The call will block until one of the following conditions is true:
0476 
0477     @li The entire message is written.
0478 
0479     @li An error occurs.
0480 
0481     This operation is implemented in terms of one or more calls to the stream's
0482     `write_some` function. The algorithm will use a temporary @ref serializer
0483     with an empty chunk decorator to produce buffers.
0484 
0485     @note This function only participates in overload resolution
0486     if @ref is_mutable_body_writer for <em>Body</em> returns `true`.
0487 
0488     @param stream The stream to which the data is to be written.
0489     The type must support the <em>SyncWriteStream</em> concept.
0490 
0491     @param msg The message to write.
0492 
0493     @return The number of bytes written to the stream.
0494 
0495     @throws system_error Thrown on failure.
0496 
0497     @see message
0498 */
0499 template<
0500     class SyncWriteStream,
0501     bool isRequest, class Body, class Fields>
0502 #if BOOST_BEAST_DOXYGEN
0503 std::size_t
0504 #else
0505 typename std::enable_if<
0506     is_mutable_body_writer<Body>::value,
0507     std::size_t>::type
0508 #endif
0509 write(
0510     SyncWriteStream& stream,
0511     message<isRequest, Body, Fields>& msg);
0512 
0513 /** Write a complete message to a stream.
0514 
0515     This function is used to write a complete message to a stream using
0516     HTTP/1. The call will block until one of the following conditions is true:
0517 
0518     @li The entire message is written.
0519 
0520     @li An error occurs.
0521 
0522     This operation is implemented in terms of one or more calls to the stream's
0523     `write_some` function. The algorithm will use a temporary @ref serializer
0524     with an empty chunk decorator to produce buffers.
0525 
0526     @note This function only participates in overload resolution
0527     if @ref is_mutable_body_writer for <em>Body</em> returns `false`.
0528 
0529     @param stream The stream to which the data is to be written.
0530     The type must support the <em>SyncWriteStream</em> concept.
0531 
0532     @param msg The message to write.
0533 
0534     @return The number of bytes written to the stream.
0535 
0536     @throws system_error Thrown on failure.
0537 
0538     @see message
0539 */
0540 template<
0541     class SyncWriteStream,
0542     bool isRequest, class Body, class Fields>
0543 #if BOOST_BEAST_DOXYGEN
0544 std::size_t
0545 #else
0546 typename std::enable_if<
0547     ! is_mutable_body_writer<Body>::value,
0548     std::size_t>::type
0549 #endif
0550 write(
0551     SyncWriteStream& stream,
0552     message<isRequest, Body, Fields> const& msg);
0553 
0554 /** Write a complete message to a stream.
0555 
0556     This function is used to write a complete message to a stream using
0557     HTTP/1. The call will block until one of the following conditions is true:
0558 
0559     @li The entire message is written.
0560 
0561     @li An error occurs.
0562 
0563     This operation is implemented in terms of one or more calls to the stream's
0564     `write_some` function. The algorithm will use a temporary @ref serializer
0565     with an empty chunk decorator to produce buffers.
0566 
0567     @note This function only participates in overload resolution
0568     if @ref is_mutable_body_writer for <em>Body</em> returns `true`.
0569 
0570     @param stream The stream to which the data is to be written.
0571     The type must support the <em>SyncWriteStream</em> concept.
0572 
0573     @param msg The message to write.
0574 
0575     @param ec Set to the error, if any occurred.
0576 
0577     @return The number of bytes written to the stream.
0578 
0579     @see message
0580 */
0581 template<
0582     class SyncWriteStream,
0583     bool isRequest, class Body, class Fields>
0584 #if BOOST_BEAST_DOXYGEN
0585 std::size_t
0586 #else
0587 typename std::enable_if<
0588     is_mutable_body_writer<Body>::value,
0589     std::size_t>::type
0590 #endif
0591 write(
0592     SyncWriteStream& stream,
0593     message<isRequest, Body, Fields>& msg,
0594     error_code& ec);
0595 
0596 /** Write a complete message to a stream.
0597 
0598     This function is used to write a complete message to a stream using
0599     HTTP/1. The call will block until one of the following conditions is true:
0600 
0601     @li The entire message is written.
0602 
0603     @li An error occurs.
0604 
0605     This operation is implemented in terms of one or more calls to the stream's
0606     `write_some` function. The algorithm will use a temporary @ref serializer
0607     with an empty chunk decorator to produce buffers.
0608 
0609     @note This function only participates in overload resolution
0610     if @ref is_mutable_body_writer for <em>Body</em> returns `false`.
0611 
0612     @param stream The stream to which the data is to be written.
0613     The type must support the <em>SyncWriteStream</em> concept.
0614 
0615     @param msg The message to write.
0616 
0617     @param ec Set to the error, if any occurred.
0618 
0619     @return The number of bytes written to the stream.
0620 
0621     @see message
0622 */
0623 template<
0624     class SyncWriteStream,
0625     bool isRequest, class Body, class Fields>
0626 #if BOOST_BEAST_DOXYGEN
0627 std::size_t
0628 #else
0629 typename std::enable_if<
0630     ! is_mutable_body_writer<Body>::value,
0631     std::size_t>::type
0632 #endif
0633 write(
0634     SyncWriteStream& stream,
0635     message<isRequest, Body, Fields> const& msg,
0636     error_code& ec);
0637 
0638 /** Write a complete message to a stream asynchronously.
0639 
0640     This function is used to write a complete message to a stream asynchronously
0641     using HTTP/1. The function call always returns immediately. The asynchronous
0642     operation will continue until one of the following conditions is true:
0643 
0644     @li The entire message is written.
0645 
0646     @li An error occurs.
0647 
0648     This operation is implemented in terms of zero or more calls to the stream's
0649     `async_write_some` function, and is known as a <em>composed operation</em>.
0650     The program must ensure that the stream performs no other writes
0651     until this operation completes. The algorithm will use a temporary
0652     @ref serializer with an empty chunk decorator to produce buffers.
0653 
0654     @note This function only participates in overload resolution
0655     if @ref is_mutable_body_writer for <em>Body</em> returns `true`.
0656 
0657     @param stream The stream to which the data is to be written.
0658     The type must support the <em>AsyncWriteStream</em> concept.
0659 
0660     @param msg The message to write.
0661     The object must remain valid at least until the
0662     handler is called; ownership is not transferred.
0663 
0664     @param handler The completion handler to invoke when the operation
0665     completes. The implementation takes ownership of the handler by
0666     performing a decay-copy. The equivalent function signature of
0667     the handler must be:
0668     @code
0669     void handler(
0670         error_code const& error,        // result of operation
0671         std::size_t bytes_transferred   // the number of bytes written to the stream
0672     );
0673     @endcode
0674     If the handler has an associated immediate executor,
0675     an immediate completion will be dispatched to it.
0676     Otherwise, the handler will not be invoked from within
0677     this function. Invocation of the handler will be performed in a
0678     manner equivalent to using `net::post`.
0679 
0680     @par Per-Operation Cancellation
0681 
0682     This asynchronous operation supports cancellation for the following
0683     net::cancellation_type values:
0684 
0685     @li @c net::cancellation_type::terminal
0686 
0687     if the `stream` also supports terminal cancellation.
0688 
0689     `terminal` cancellation leaves the stream in an undefined state,
0690     so that only closing it is guaranteed to succeed.
0691 
0692     @see message
0693 */
0694 template<
0695     class AsyncWriteStream,
0696     bool isRequest, class Body, class Fields,
0697     BOOST_BEAST_ASYNC_TPARAM2 WriteHandler =
0698         net::default_completion_token_t<
0699             executor_type<AsyncWriteStream>>>
0700 BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
0701 async_write(
0702     AsyncWriteStream& stream,
0703     message<isRequest, Body, Fields>& msg,
0704     WriteHandler&& handler =
0705         net::default_completion_token_t<
0706             executor_type<AsyncWriteStream>>{}
0707 #ifndef BOOST_BEAST_DOXYGEN
0708     , typename std::enable_if<
0709         is_mutable_body_writer<Body>::value>::type* = 0
0710 #endif
0711     );
0712 
0713 /** Write a complete message to a stream asynchronously.
0714 
0715     This function is used to write a complete message to a stream asynchronously
0716     using HTTP/1. The function call always returns immediately. The asynchronous
0717     operation will continue until one of the following conditions is true:
0718 
0719     @li The entire message is written.
0720 
0721     @li An error occurs.
0722 
0723     This operation is implemented in terms of zero or more calls to the stream's
0724     `async_write_some` function, and is known as a <em>composed operation</em>.
0725     The program must ensure that the stream performs no other writes
0726     until this operation completes. The algorithm will use a temporary
0727     @ref serializer with an empty chunk decorator to produce buffers.
0728 
0729     @note This function only participates in overload resolution
0730     if @ref is_mutable_body_writer for <em>Body</em> returns `false`.
0731 
0732     @param stream The stream to which the data is to be written.
0733     The type must support the <em>AsyncWriteStream</em> concept.
0734 
0735     @param msg The message to write.
0736     The object must remain valid at least until the
0737     handler is called; ownership is not transferred.
0738 
0739     @param handler The completion handler to invoke when the operation
0740     completes. The implementation takes ownership of the handler by
0741     performing a decay-copy. The equivalent function signature of
0742     the handler must be:
0743     @code
0744     void handler(
0745         error_code const& error,        // result of operation
0746         std::size_t bytes_transferred   // the number of bytes written to the stream
0747     );
0748     @endcode
0749     If the handler has an associated immediate executor,
0750     an immediate completion will be dispatched to it.
0751     Otherwise, the handler will not be invoked from within
0752     this function. Invocation of the handler will be performed in a
0753     manner equivalent to using `net::post`.
0754 
0755     @par Per-Operation Cancellation
0756 
0757     This asynchronous operation supports cancellation for the following
0758     net::cancellation_type values:
0759 
0760     @li @c net::cancellation_type::terminal
0761 
0762     if the `stream` also supports terminal cancellation.
0763 
0764     `terminal` cancellation leaves the stream in an undefined state,
0765     so that only closing it is guaranteed to succeed.
0766 
0767     @see message
0768 */
0769 template<
0770     class AsyncWriteStream,
0771     bool isRequest, class Body, class Fields,
0772     BOOST_BEAST_ASYNC_TPARAM2 WriteHandler =
0773         net::default_completion_token_t<
0774             executor_type<AsyncWriteStream>>>
0775 BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
0776 async_write(
0777     AsyncWriteStream& stream,
0778     message<isRequest, Body, Fields> const& msg,
0779     WriteHandler&& handler =
0780         net::default_completion_token_t<
0781             executor_type<AsyncWriteStream>>{}
0782 #ifndef BOOST_BEAST_DOXYGEN
0783     , typename std::enable_if<
0784         ! is_mutable_body_writer<Body>::value>::type* = 0
0785 #endif
0786     );
0787 
0788 
0789 //------------------------------------------------------------------------------
0790 
0791 /** Serialize an HTTP/1 header to a `std::ostream`.
0792 
0793     The function converts the header to its HTTP/1 serialized
0794     representation and stores the result in the output stream.
0795 
0796     @param os The output stream to write to.
0797 
0798     @param msg The message fields to write.
0799 */
0800 template<bool isRequest, class Fields>
0801 std::ostream&
0802 operator<<(std::ostream& os,
0803     header<isRequest, Fields> const& msg);
0804 
0805 /** Serialize an HTTP/1 message to a `std::ostream`.
0806 
0807     The function converts the message to its HTTP/1 serialized
0808     representation and stores the result in the output stream.
0809 
0810     The implementation will automatically perform chunk encoding if
0811     the contents of the message indicate that chunk encoding is required.
0812 
0813     @param os The output stream to write to.
0814 
0815     @param msg The message to write.
0816 */
0817 template<bool isRequest, class Body, class Fields>
0818 std::ostream&
0819 operator<<(std::ostream& os,
0820     message<isRequest, Body, Fields> const& msg);
0821 
0822 } // http
0823 } // beast
0824 } // boost
0825 
0826 #include <boost/beast/http/impl/write.hpp>
0827 
0828 #endif