![]() |
|
|||
File indexing completed on 2025-07-14 08:26:52
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, `terminal` 0173 cancellation leaves the stream in an undefined state, so that only 0174 closing it is guaranteed to succeed. 0175 0176 @see serializer 0177 */ 0178 template< 0179 class AsyncWriteStream, 0180 bool isRequest, class Body, class Fields, 0181 BOOST_BEAST_ASYNC_TPARAM2 WriteHandler = 0182 net::default_completion_token_t< 0183 executor_type<AsyncWriteStream>>> 0184 BOOST_BEAST_ASYNC_RESULT2(WriteHandler) 0185 async_write_some( 0186 AsyncWriteStream& stream, 0187 serializer<isRequest, Body, Fields>& sr, 0188 WriteHandler&& handler = 0189 net::default_completion_token_t< 0190 executor_type<AsyncWriteStream>>{}); 0191 0192 //------------------------------------------------------------------------------ 0193 0194 /** Write a header to a stream using a serializer. 0195 0196 This function is used to write a header to a stream using a 0197 caller-provided HTTP/1 serializer. The call will block until one 0198 of the following conditions is true: 0199 0200 @li The function @ref serializer::is_header_done returns `true` 0201 0202 @li An error occurs. 0203 0204 This operation is implemented in terms of one or more calls 0205 to the stream's `write_some` function. 0206 0207 @param stream The stream to which the data is to be written. 0208 The type must support the <em>SyncWriteStream</em> concept. 0209 0210 @param sr The serializer to use. 0211 0212 @return The number of bytes written to the stream. 0213 0214 @throws system_error Thrown on failure. 0215 0216 @note The implementation will call @ref serializer::split with 0217 the value `true` on the serializer passed in. 0218 0219 @see serializer 0220 */ 0221 template< 0222 class SyncWriteStream, 0223 bool isRequest, class Body, class Fields> 0224 std::size_t 0225 write_header( 0226 SyncWriteStream& stream, 0227 serializer<isRequest, Body, Fields>& sr); 0228 0229 /** Write a header to a stream using a serializer. 0230 0231 This function is used to write a header to a stream using a 0232 caller-provided HTTP/1 serializer. The call will block until one 0233 of the following conditions is true: 0234 0235 @li The function @ref serializer::is_header_done returns `true` 0236 0237 @li An error occurs. 0238 0239 This operation is implemented in terms of one or more calls 0240 to the stream's `write_some` function. 0241 0242 @param stream The stream to which the data is to be written. 0243 The type must support the <em>SyncWriteStream</em> concept. 0244 0245 @param sr The serializer to use. 0246 0247 @param ec Set to indicate what error occurred, if any. 0248 0249 @return The number of bytes written to the stream. 0250 0251 @note The implementation will call @ref serializer::split with 0252 the value `true` on the serializer passed in. 0253 0254 @see serializer 0255 */ 0256 template< 0257 class SyncWriteStream, 0258 bool isRequest, class Body, class Fields> 0259 std::size_t 0260 write_header( 0261 SyncWriteStream& stream, 0262 serializer<isRequest, Body, Fields>& sr, 0263 error_code& ec); 0264 0265 /** Write a header to a stream asynchronously using a serializer. 0266 0267 This function is used to write a header to a stream asynchronously 0268 using a caller-provided HTTP/1 serializer. The function call always 0269 returns immediately. The asynchronous operation will continue until 0270 one of the following conditions is true: 0271 0272 @li The function @ref serializer::is_header_done returns `true` 0273 0274 @li An error occurs. 0275 0276 This operation is implemented in terms of zero or more calls to the stream's 0277 `async_write_some` function, and is known as a <em>composed operation</em>. 0278 The program must ensure that the stream performs no other writes 0279 until this operation completes. 0280 0281 @param stream The stream to which the data is to be written. 0282 The type must support the <em>AsyncWriteStream</em> concept. 0283 0284 @param sr The serializer to use. 0285 The object must remain valid at least until the 0286 handler is called; ownership is not transferred. 0287 0288 @param handler The completion handler to invoke when the operation 0289 completes. The implementation takes ownership of the handler by 0290 performing a decay-copy. The equivalent function signature of 0291 the handler must be: 0292 @code 0293 void handler( 0294 error_code const& error, // result of operation 0295 std::size_t bytes_transferred // the number of bytes written to the stream 0296 ); 0297 @endcode 0298 If the handler has an associated immediate executor, 0299 an immediate completion will be dispatched to it. 0300 Otherwise, the handler will not be invoked from within 0301 this function. Invocation of the handler will be performed in a 0302 manner equivalent to using `net::post`. 0303 0304 @note The implementation will call @ref serializer::split with 0305 the value `true` on the serializer passed in. 0306 0307 @par Per-Operation Cancellation 0308 0309 This asynchronous operation supports cancellation for the following 0310 net::cancellation_type values: 0311 0312 @li @c net::cancellation_type::terminal 0313 0314 if the `stream` also supports terminal cancellation, `terminal` 0315 cancellation leaves the stream in an undefined state, so that only 0316 closing it is guaranteed to succeed. 0317 0318 @see serializer 0319 */ 0320 template< 0321 class AsyncWriteStream, 0322 bool isRequest, class Body, class Fields, 0323 BOOST_BEAST_ASYNC_TPARAM2 WriteHandler = 0324 net::default_completion_token_t< 0325 executor_type<AsyncWriteStream>>> 0326 BOOST_BEAST_ASYNC_RESULT2(WriteHandler) 0327 async_write_header( 0328 AsyncWriteStream& stream, 0329 serializer<isRequest, Body, Fields>& sr, 0330 WriteHandler&& handler = 0331 net::default_completion_token_t< 0332 executor_type<AsyncWriteStream>>{}); 0333 0334 //------------------------------------------------------------------------------ 0335 0336 /** Write a complete message to a stream using a serializer. 0337 0338 This function is used to write a complete message to a stream using 0339 a caller-provided HTTP/1 serializer. The call will block until one 0340 of the following conditions is true: 0341 0342 @li The function @ref serializer::is_done returns `true` 0343 0344 @li An error occurs. 0345 0346 This operation is implemented in terms of one or more calls 0347 to the stream's `write_some` function. 0348 0349 @param stream The stream to which the data is to be written. 0350 The type must support the <em>SyncWriteStream</em> concept. 0351 0352 @param sr The serializer to use. 0353 0354 @return The number of bytes written to the stream. 0355 0356 @throws system_error Thrown on failure. 0357 0358 @see serializer 0359 */ 0360 template< 0361 class SyncWriteStream, 0362 bool isRequest, class Body, class Fields> 0363 std::size_t 0364 write( 0365 SyncWriteStream& stream, 0366 serializer<isRequest, Body, Fields>& sr); 0367 0368 /** Write a complete message to a stream using a serializer. 0369 0370 This function is used to write a complete message to a stream using 0371 a caller-provided HTTP/1 serializer. The call will block until one 0372 of the following conditions is true: 0373 0374 @li The function @ref serializer::is_done returns `true` 0375 0376 @li An error occurs. 0377 0378 This operation is implemented in terms of one or more calls 0379 to the stream's `write_some` function. 0380 0381 @param stream The stream to which the data is to be written. 0382 The type must support the <em>SyncWriteStream</em> concept. 0383 0384 @param sr The serializer to use. 0385 0386 @param ec Set to the error, if any occurred. 0387 0388 @return The number of bytes written to the stream. 0389 0390 @see serializer 0391 */ 0392 template< 0393 class SyncWriteStream, 0394 bool isRequest, class Body, class Fields> 0395 std::size_t 0396 write( 0397 SyncWriteStream& stream, 0398 serializer<isRequest, Body, Fields>& sr, 0399 error_code& ec); 0400 0401 /** Write a complete message to a stream asynchronously using a serializer. 0402 0403 This function is used to write a complete message to a stream 0404 asynchronously using a caller-provided HTTP/1 serializer. The 0405 function call always returns immediately. The asynchronous 0406 operation will continue until one of the following conditions is true: 0407 0408 @li The function @ref serializer::is_done returns `true` 0409 0410 @li An error occurs. 0411 0412 This operation is implemented in terms of zero or more calls to the stream's 0413 `async_write_some` function, and is known as a <em>composed operation</em>. 0414 The program must ensure that the stream performs no other writes 0415 until this operation completes. 0416 0417 @param stream The stream to which the data is to be written. 0418 The type must support the <em>AsyncWriteStream</em> concept. 0419 0420 @param sr The serializer to use. 0421 The object must remain valid at least until the 0422 handler is called; ownership is not transferred. 0423 0424 @param handler The completion handler to invoke when the operation 0425 completes. The implementation takes ownership of the handler by 0426 performing a decay-copy. The equivalent function signature of 0427 the handler must be: 0428 @code 0429 void handler( 0430 error_code const& error, // result of operation 0431 std::size_t bytes_transferred // the number of bytes written to the stream 0432 ); 0433 @endcode 0434 If the handler has an associated immediate executor, 0435 an immediate completion will be dispatched to it. 0436 Otherwise, the handler will not be invoked from within 0437 this function. Invocation of the handler will be performed in a 0438 manner equivalent to using `net::post`. 0439 0440 @par Per-Operation Cancellation 0441 0442 This asynchronous operation supports cancellation for the following 0443 net::cancellation_type values: 0444 0445 @li @c net::cancellation_type::terminal 0446 0447 if the `stream` also supports terminal cancellation, `terminal` 0448 cancellation leaves the stream in an undefined state, so that only 0449 closing it is guaranteed to succeed. 0450 0451 @see serializer 0452 */ 0453 template< 0454 class AsyncWriteStream, 0455 bool isRequest, class Body, class Fields, 0456 BOOST_BEAST_ASYNC_TPARAM2 WriteHandler = 0457 net::default_completion_token_t< 0458 executor_type<AsyncWriteStream>>> 0459 BOOST_BEAST_ASYNC_RESULT2(WriteHandler) 0460 async_write( 0461 AsyncWriteStream& stream, 0462 serializer<isRequest, Body, Fields>& sr, 0463 WriteHandler&& handler = 0464 net::default_completion_token_t< 0465 executor_type<AsyncWriteStream>>{}); 0466 0467 //------------------------------------------------------------------------------ 0468 0469 /** Write a complete message to a stream. 0470 0471 This function is used to write a complete message to a stream using 0472 HTTP/1. The call will block until one of the following conditions is true: 0473 0474 @li The entire message is written. 0475 0476 @li An error occurs. 0477 0478 This operation is implemented in terms of one or more calls to the stream's 0479 `write_some` function. The algorithm will use a temporary @ref serializer 0480 with an empty chunk decorator to produce buffers. 0481 0482 @note This function only participates in overload resolution 0483 if @ref is_mutable_body_writer for <em>Body</em> returns `true`. 0484 0485 @param stream The stream to which the data is to be written. 0486 The type must support the <em>SyncWriteStream</em> concept. 0487 0488 @param msg The message to write. 0489 0490 @return The number of bytes written to the stream. 0491 0492 @throws system_error Thrown on failure. 0493 0494 @see message 0495 */ 0496 template< 0497 class SyncWriteStream, 0498 bool isRequest, class Body, class Fields> 0499 #if BOOST_BEAST_DOXYGEN 0500 std::size_t 0501 #else 0502 typename std::enable_if< 0503 is_mutable_body_writer<Body>::value, 0504 std::size_t>::type 0505 #endif 0506 write( 0507 SyncWriteStream& stream, 0508 message<isRequest, Body, Fields>& msg); 0509 0510 /** Write a complete message to a stream. 0511 0512 This function is used to write a complete message to a stream using 0513 HTTP/1. The call will block until one of the following conditions is true: 0514 0515 @li The entire message is written. 0516 0517 @li An error occurs. 0518 0519 This operation is implemented in terms of one or more calls to the stream's 0520 `write_some` function. The algorithm will use a temporary @ref serializer 0521 with an empty chunk decorator to produce buffers. 0522 0523 @note This function only participates in overload resolution 0524 if @ref is_mutable_body_writer for <em>Body</em> returns `false`. 0525 0526 @param stream The stream to which the data is to be written. 0527 The type must support the <em>SyncWriteStream</em> concept. 0528 0529 @param msg The message to write. 0530 0531 @return The number of bytes written to the stream. 0532 0533 @throws system_error Thrown on failure. 0534 0535 @see message 0536 */ 0537 template< 0538 class SyncWriteStream, 0539 bool isRequest, class Body, class Fields> 0540 #if BOOST_BEAST_DOXYGEN 0541 std::size_t 0542 #else 0543 typename std::enable_if< 0544 ! is_mutable_body_writer<Body>::value, 0545 std::size_t>::type 0546 #endif 0547 write( 0548 SyncWriteStream& stream, 0549 message<isRequest, Body, Fields> const& msg); 0550 0551 /** Write a complete message to a stream. 0552 0553 This function is used to write a complete message to a stream using 0554 HTTP/1. The call will block until one of the following conditions is true: 0555 0556 @li The entire message is written. 0557 0558 @li An error occurs. 0559 0560 This operation is implemented in terms of one or more calls to the stream's 0561 `write_some` function. The algorithm will use a temporary @ref serializer 0562 with an empty chunk decorator to produce buffers. 0563 0564 @note This function only participates in overload resolution 0565 if @ref is_mutable_body_writer for <em>Body</em> returns `true`. 0566 0567 @param stream The stream to which the data is to be written. 0568 The type must support the <em>SyncWriteStream</em> concept. 0569 0570 @param msg The message to write. 0571 0572 @param ec Set to the error, if any occurred. 0573 0574 @return The number of bytes written to the stream. 0575 0576 @see message 0577 */ 0578 template< 0579 class SyncWriteStream, 0580 bool isRequest, class Body, class Fields> 0581 #if BOOST_BEAST_DOXYGEN 0582 std::size_t 0583 #else 0584 typename std::enable_if< 0585 is_mutable_body_writer<Body>::value, 0586 std::size_t>::type 0587 #endif 0588 write( 0589 SyncWriteStream& stream, 0590 message<isRequest, Body, Fields>& msg, 0591 error_code& ec); 0592 0593 /** Write a complete message to a stream. 0594 0595 This function is used to write a complete message to a stream using 0596 HTTP/1. The call will block until one of the following conditions is true: 0597 0598 @li The entire message is written. 0599 0600 @li An error occurs. 0601 0602 This operation is implemented in terms of one or more calls to the stream's 0603 `write_some` function. The algorithm will use a temporary @ref serializer 0604 with an empty chunk decorator to produce buffers. 0605 0606 @note This function only participates in overload resolution 0607 if @ref is_mutable_body_writer for <em>Body</em> returns `false`. 0608 0609 @param stream The stream to which the data is to be written. 0610 The type must support the <em>SyncWriteStream</em> concept. 0611 0612 @param msg The message to write. 0613 0614 @param ec Set to the error, if any occurred. 0615 0616 @return The number of bytes written to the stream. 0617 0618 @see message 0619 */ 0620 template< 0621 class SyncWriteStream, 0622 bool isRequest, class Body, class Fields> 0623 #if BOOST_BEAST_DOXYGEN 0624 std::size_t 0625 #else 0626 typename std::enable_if< 0627 ! is_mutable_body_writer<Body>::value, 0628 std::size_t>::type 0629 #endif 0630 write( 0631 SyncWriteStream& stream, 0632 message<isRequest, Body, Fields> const& msg, 0633 error_code& ec); 0634 0635 /** Write a complete message to a stream asynchronously. 0636 0637 This function is used to write a complete message to a stream asynchronously 0638 using HTTP/1. The function call always returns immediately. The asynchronous 0639 operation will continue until one of the following conditions is true: 0640 0641 @li The entire message is written. 0642 0643 @li An error occurs. 0644 0645 This operation is implemented in terms of zero or more calls to the stream's 0646 `async_write_some` function, and is known as a <em>composed operation</em>. 0647 The program must ensure that the stream performs no other writes 0648 until this operation completes. The algorithm will use a temporary 0649 @ref serializer with an empty chunk decorator to produce buffers. 0650 0651 @note This function only participates in overload resolution 0652 if @ref is_mutable_body_writer for <em>Body</em> returns `true`. 0653 0654 @param stream The stream to which the data is to be written. 0655 The type must support the <em>AsyncWriteStream</em> concept. 0656 0657 @param msg The message to write. 0658 The object must remain valid at least until the 0659 handler is called; ownership is not transferred. 0660 0661 @param handler The completion handler to invoke when the operation 0662 completes. The implementation takes ownership of the handler by 0663 performing a decay-copy. The equivalent function signature of 0664 the handler must be: 0665 @code 0666 void handler( 0667 error_code const& error, // result of operation 0668 std::size_t bytes_transferred // the number of bytes written to the stream 0669 ); 0670 @endcode 0671 If the handler has an associated immediate executor, 0672 an immediate completion will be dispatched to it. 0673 Otherwise, the handler will not be invoked from within 0674 this function. Invocation of the handler will be performed in a 0675 manner equivalent to using `net::post`. 0676 0677 @par Per-Operation Cancellation 0678 0679 This asynchronous operation supports cancellation for the following 0680 net::cancellation_type values: 0681 0682 @li @c net::cancellation_type::terminal 0683 0684 if the `stream` also supports terminal cancellation, `terminal` 0685 cancellation leaves the stream in an undefined state, so that only 0686 closing it is guaranteed to succeed. 0687 0688 @see message 0689 */ 0690 template< 0691 class AsyncWriteStream, 0692 bool isRequest, class Body, class Fields, 0693 BOOST_BEAST_ASYNC_TPARAM2 WriteHandler = 0694 net::default_completion_token_t< 0695 executor_type<AsyncWriteStream>>> 0696 BOOST_BEAST_ASYNC_RESULT2(WriteHandler) 0697 async_write( 0698 AsyncWriteStream& stream, 0699 message<isRequest, Body, Fields>& msg, 0700 WriteHandler&& handler = 0701 net::default_completion_token_t< 0702 executor_type<AsyncWriteStream>>{} 0703 #ifndef BOOST_BEAST_DOXYGEN 0704 , typename std::enable_if< 0705 is_mutable_body_writer<Body>::value>::type* = 0 0706 #endif 0707 ); 0708 0709 /** Write a complete message to a stream asynchronously. 0710 0711 This function is used to write a complete message to a stream asynchronously 0712 using HTTP/1. The function call always returns immediately. The asynchronous 0713 operation will continue until one of the following conditions is true: 0714 0715 @li The entire message is written. 0716 0717 @li An error occurs. 0718 0719 This operation is implemented in terms of zero or more calls to the stream's 0720 `async_write_some` function, and is known as a <em>composed operation</em>. 0721 The program must ensure that the stream performs no other writes 0722 until this operation completes. The algorithm will use a temporary 0723 @ref serializer with an empty chunk decorator to produce buffers. 0724 0725 @note This function only participates in overload resolution 0726 if @ref is_mutable_body_writer for <em>Body</em> returns `false`. 0727 0728 @param stream The stream to which the data is to be written. 0729 The type must support the <em>AsyncWriteStream</em> concept. 0730 0731 @param msg The message to write. 0732 The object must remain valid at least until the 0733 handler is called; ownership is not transferred. 0734 0735 @param handler The completion handler to invoke when the operation 0736 completes. The implementation takes ownership of the handler by 0737 performing a decay-copy. The equivalent function signature of 0738 the handler must be: 0739 @code 0740 void handler( 0741 error_code const& error, // result of operation 0742 std::size_t bytes_transferred // the number of bytes written to the stream 0743 ); 0744 @endcode 0745 If the handler has an associated immediate executor, 0746 an immediate completion will be dispatched to it. 0747 Otherwise, the handler will not be invoked from within 0748 this function. Invocation of the handler will be performed in a 0749 manner equivalent to using `net::post`. 0750 0751 @par Per-Operation Cancellation 0752 0753 This asynchronous operation supports cancellation for the following 0754 net::cancellation_type values: 0755 0756 @li @c net::cancellation_type::terminal 0757 0758 if the `stream` also supports terminal cancellation, `terminal` 0759 cancellation leaves the stream in an undefined state, so that only 0760 closing it is guaranteed to succeed. 0761 0762 @see message 0763 */ 0764 template< 0765 class AsyncWriteStream, 0766 bool isRequest, class Body, class Fields, 0767 BOOST_BEAST_ASYNC_TPARAM2 WriteHandler = 0768 net::default_completion_token_t< 0769 executor_type<AsyncWriteStream>>> 0770 BOOST_BEAST_ASYNC_RESULT2(WriteHandler) 0771 async_write( 0772 AsyncWriteStream& stream, 0773 message<isRequest, Body, Fields> const& msg, 0774 WriteHandler&& handler = 0775 net::default_completion_token_t< 0776 executor_type<AsyncWriteStream>>{} 0777 #ifndef BOOST_BEAST_DOXYGEN 0778 , typename std::enable_if< 0779 ! is_mutable_body_writer<Body>::value>::type* = 0 0780 #endif 0781 ); 0782 0783 0784 //------------------------------------------------------------------------------ 0785 0786 /** Serialize an HTTP/1 header to a `std::ostream`. 0787 0788 The function converts the header to its HTTP/1 serialized 0789 representation and stores the result in the output stream. 0790 0791 @param os The output stream to write to. 0792 0793 @param msg The message fields to write. 0794 */ 0795 template<bool isRequest, class Fields> 0796 std::ostream& 0797 operator<<(std::ostream& os, 0798 header<isRequest, Fields> const& msg); 0799 0800 /** Serialize an HTTP/1 message to a `std::ostream`. 0801 0802 The function converts the message to its HTTP/1 serialized 0803 representation and stores the result in the output stream. 0804 0805 The implementation will automatically perform chunk encoding if 0806 the contents of the message indicate that chunk encoding is required. 0807 0808 @param os The output stream to write to. 0809 0810 @param msg The message to write. 0811 */ 0812 template<bool isRequest, class Body, class Fields> 0813 std::ostream& 0814 operator<<(std::ostream& os, 0815 message<isRequest, Body, Fields> const& msg); 0816 0817 } // http 0818 } // beast 0819 } // boost 0820 0821 #include <boost/beast/http/impl/write.hpp> 0822 0823 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |