2017-07-20 08:01:46 -07:00
|
|
|
//
|
2017-02-06 20:07:03 -05:00
|
|
|
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2017-07-20 08:01:46 -07:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef BEAST_HTTP_WRITE_HPP
|
|
|
|
#define BEAST_HTTP_WRITE_HPP
|
|
|
|
|
2017-04-10 19:24:27 -07:00
|
|
|
#include <beast/config.hpp>
|
2017-05-08 12:41:45 -07:00
|
|
|
#include <beast/core/buffer_cat.hpp>
|
|
|
|
#include <beast/core/consuming_buffers.hpp>
|
|
|
|
#include <beast/core/multi_buffer.hpp>
|
2016-10-09 06:34:35 -04:00
|
|
|
#include <beast/http/message.hpp>
|
2017-05-28 17:04:39 -07:00
|
|
|
#include <beast/http/serializer.hpp>
|
2017-05-08 12:41:45 -07:00
|
|
|
#include <beast/http/detail/chunk_encode.hpp>
|
2016-05-07 14:57:15 -04:00
|
|
|
#include <beast/core/error.hpp>
|
2017-05-06 12:36:40 -07:00
|
|
|
#include <beast/core/async_result.hpp>
|
2017-06-16 09:38:53 -07:00
|
|
|
#include <beast/core/string.hpp>
|
2017-05-08 12:41:45 -07:00
|
|
|
#include <boost/variant.hpp>
|
2017-06-04 15:35:21 -07:00
|
|
|
#include <iosfwd>
|
2017-05-08 12:41:45 -07:00
|
|
|
#include <limits>
|
|
|
|
#include <memory>
|
2017-07-20 08:01:46 -07:00
|
|
|
#include <type_traits>
|
2017-05-08 12:41:45 -07:00
|
|
|
#include <utility>
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
namespace beast {
|
|
|
|
namespace http {
|
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
/** Write part of a message to a stream using a serializer.
|
2016-11-07 12:20:39 -05:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
This function is used to write part of a message to a stream using
|
|
|
|
a caller-provided HTTP/1 serializer. The call will block until one
|
|
|
|
of the following conditions is true:
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-28 17:04:39 -07:00
|
|
|
@li One or more bytes have been transferred.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
@li The function @ref serializer::is_done returns `true`
|
|
|
|
|
2017-05-28 17:04:39 -07:00
|
|
|
@li An error occurs on the stream.
|
2017-05-28 09:05:29 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
This operation is implemented in terms of one or more calls
|
|
|
|
to the stream's `write_some` function.
|
|
|
|
|
|
|
|
The amount of data actually transferred is controlled by the behavior
|
|
|
|
of the underlying stream, performing bounded work for each call. This
|
|
|
|
helps applications set reasonable timeouts. It also allows application-level
|
|
|
|
flow control to function correctly. For example when using a TCP/IP based
|
|
|
|
stream.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
@param stream The stream to which the data is to be written.
|
|
|
|
The type must support the @b SyncWriteStream concept.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-28 17:04:39 -07:00
|
|
|
@param sr The serializer to use.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-28 17:04:39 -07:00
|
|
|
@throws system_error Thrown on failure.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
@see serializer
|
2017-05-28 17:04:39 -07:00
|
|
|
*/
|
2017-06-07 05:10:58 -07:00
|
|
|
template<class SyncWriteStream, bool isRequest,
|
|
|
|
class Body, class Fields, class Decorator>
|
2017-05-28 17:04:39 -07:00
|
|
|
void
|
|
|
|
write_some(SyncWriteStream& stream, serializer<
|
2017-06-07 05:10:58 -07:00
|
|
|
isRequest, Body, Fields, Decorator>& sr);
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
/** Write part of a message to a stream using a serializer.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
This function is used to write part of a message to a stream using
|
|
|
|
a caller-provided HTTP/1 serializer. The call will block until one
|
|
|
|
of the following conditions is true:
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-28 17:04:39 -07:00
|
|
|
@li One or more bytes have been transferred.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
@li The function @ref serializer::is_done returns `true`
|
|
|
|
|
2017-05-28 17:04:39 -07:00
|
|
|
@li An error occurs on the stream.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
This operation is implemented in terms of one or more calls
|
|
|
|
to the stream's `write_some` function.
|
|
|
|
|
|
|
|
The amount of data actually transferred is controlled by the behavior
|
|
|
|
of the underlying stream, performing bounded work for each call. This
|
|
|
|
helps applications set reasonable timeouts. It also allows application-level
|
|
|
|
flow control to function correctly. For example when using a TCP/IP based
|
|
|
|
stream.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
@param stream The stream to which the data is to be written.
|
|
|
|
The type must support the @b SyncWriteStream concept.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-28 17:04:39 -07:00
|
|
|
@param sr The serializer to use.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-28 17:04:39 -07:00
|
|
|
@param ec Set to indicate what error occurred, if any.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-28 17:04:39 -07:00
|
|
|
@see @ref async_write_some, @ref serializer
|
|
|
|
*/
|
2017-06-07 05:10:58 -07:00
|
|
|
template<class SyncWriteStream, bool isRequest,
|
|
|
|
class Body, class Fields, class Decorator>
|
2017-05-28 17:04:39 -07:00
|
|
|
void
|
|
|
|
write_some(SyncWriteStream& stream, serializer<
|
2017-06-07 05:10:58 -07:00
|
|
|
isRequest, Body, Fields, Decorator>& sr,
|
2017-05-28 17:04:39 -07:00
|
|
|
error_code& ec);
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
/** Write part of a message to a stream asynchronously using a serializer.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
This function is used to write part of a message to a stream
|
|
|
|
asynchronously using a caller-provided HTTP/1 serializer. The function
|
|
|
|
call always returns immediately. The asynchronous operation will continue
|
|
|
|
until one of the following conditions is true:
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-28 17:04:39 -07:00
|
|
|
@li One or more bytes have been transferred.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
@li The function @ref serializer::is_done returns `true`
|
|
|
|
|
2017-05-28 17:04:39 -07:00
|
|
|
@li An error occurs on the stream.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
This operation is implemented in terms of zero or more calls to the stream's
|
|
|
|
`async_write_some` function, and is known as a <em>composed operation</em>.
|
|
|
|
The program must ensure that the stream performs no other write operations
|
|
|
|
until this operation completes.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
The amount of data actually transferred is controlled by the behavior
|
|
|
|
of the underlying stream, performing bounded work for each call. This
|
|
|
|
helps applications set reasonable timeouts. It also allows application-level
|
|
|
|
flow control to function correctly. For example when using a TCP/IP based
|
|
|
|
stream.
|
|
|
|
|
|
|
|
@param stream The stream to which the data is to be written.
|
|
|
|
The type must support the @b AsyncWriteStream concept.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
@param sr The serializer to use.
|
2017-06-03 09:45:09 -07:00
|
|
|
The object must remain valid at least until the
|
|
|
|
handler is called; ownership is not transferred.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
@param handler The handler to be called when the operation
|
|
|
|
completes. Copies will be made of the handler as required.
|
|
|
|
The equivalent function signature of the handler must be:
|
2017-05-28 17:04:39 -07:00
|
|
|
@code void handler(
|
2017-05-31 08:01:55 -07:00
|
|
|
error_code const& error // result of operation
|
2017-05-28 17:04:39 -07:00
|
|
|
); @endcode
|
|
|
|
Regardless of whether the asynchronous operation completes
|
|
|
|
immediately or not, the handler will not be invoked from within
|
|
|
|
this function. Invocation of the handler will be performed in a
|
|
|
|
manner equivalent to using `boost::asio::io_service::post`.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
@see @ref serializer
|
2017-05-28 17:04:39 -07:00
|
|
|
*/
|
|
|
|
template<class AsyncWriteStream,
|
|
|
|
bool isRequest, class Body, class Fields,
|
2017-06-07 05:10:58 -07:00
|
|
|
class Decorator, class WriteHandler>
|
2017-05-23 15:50:15 -07:00
|
|
|
#if BEAST_DOXYGEN
|
|
|
|
void_or_deduced
|
|
|
|
#else
|
2017-05-28 17:04:39 -07:00
|
|
|
async_return_type<WriteHandler, void(error_code)>
|
2017-05-23 15:50:15 -07:00
|
|
|
#endif
|
2017-05-28 17:04:39 -07:00
|
|
|
async_write_some(AsyncWriteStream& stream, serializer<
|
2017-06-07 05:10:58 -07:00
|
|
|
isRequest, Body, Fields, Decorator>& sr,
|
2016-11-07 12:20:39 -05:00
|
|
|
WriteHandler&& handler);
|
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/** Write a header to a stream using a serializer.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
This function is used to write a header to a stream using a
|
|
|
|
caller-provided HTTP/1 serializer. The call will block until one
|
|
|
|
of the following conditions is true:
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
@li The function @ref serializer::is_header_done returns `true`
|
|
|
|
|
|
|
|
@li An error occurs.
|
|
|
|
|
|
|
|
This operation is implemented in terms of one or more calls
|
|
|
|
to the stream's `write_some` function.
|
|
|
|
|
|
|
|
@param stream The stream to which the data is to be written.
|
|
|
|
The type must support the @b SyncWriteStream concept.
|
|
|
|
|
|
|
|
@param sr The serializer to use.
|
|
|
|
|
|
|
|
@throws system_error Thrown on failure.
|
|
|
|
|
|
|
|
@note The implementation will call @ref serializer::split with
|
|
|
|
the value `true` on the serializer passed in.
|
|
|
|
|
|
|
|
@see @ref serializer
|
|
|
|
*/
|
2017-06-07 05:10:58 -07:00
|
|
|
template<class SyncWriteStream, bool isRequest,
|
|
|
|
class Body, class Fields, class Decorator>
|
2017-05-31 08:01:55 -07:00
|
|
|
void
|
|
|
|
write_header(SyncWriteStream& stream, serializer<
|
2017-06-07 05:10:58 -07:00
|
|
|
isRequest, Body, Fields, Decorator>& sr);
|
2017-05-31 08:01:55 -07:00
|
|
|
|
|
|
|
/** Write a header to a stream using a serializer.
|
|
|
|
|
|
|
|
This function is used to write a header to a stream using a
|
|
|
|
caller-provided HTTP/1 serializer. The call will block until one
|
|
|
|
of the following conditions is true:
|
|
|
|
|
|
|
|
@li The function @ref serializer::is_header_done returns `true`
|
|
|
|
|
|
|
|
@li An error occurs.
|
|
|
|
|
|
|
|
This operation is implemented in terms of one or more calls
|
|
|
|
to the stream's `write_some` function.
|
|
|
|
|
|
|
|
@param stream The stream to which the data is to be written.
|
|
|
|
The type must support the @b SyncWriteStream concept.
|
|
|
|
|
|
|
|
@param sr The serializer to use.
|
|
|
|
|
|
|
|
@param ec Set to indicate what error occurred, if any.
|
|
|
|
|
|
|
|
@note The implementation will call @ref serializer::split with
|
|
|
|
the value `true` on the serializer passed in.
|
|
|
|
|
|
|
|
@see @ref serializer
|
|
|
|
*/
|
2017-06-07 05:10:58 -07:00
|
|
|
template<class SyncWriteStream, bool isRequest,
|
|
|
|
class Body, class Fields, class Decorator>
|
2017-05-31 08:01:55 -07:00
|
|
|
void
|
|
|
|
write_header(SyncWriteStream& stream, serializer<
|
2017-06-07 05:10:58 -07:00
|
|
|
isRequest, Body, Fields, Decorator>& sr,
|
2017-05-31 08:01:55 -07:00
|
|
|
error_code& ec);
|
|
|
|
|
|
|
|
/** Write a header to a stream asynchronously using a serializer.
|
|
|
|
|
|
|
|
This function is used to write a header to a stream asynchronously
|
|
|
|
using a caller-provided HTTP/1 serializer. The function call always
|
|
|
|
returns immediately. The asynchronous operation will continue until
|
|
|
|
one of the following conditions is true:
|
|
|
|
|
|
|
|
@li The function @ref serializer::is_header_done returns `true`
|
|
|
|
|
|
|
|
@li An error occurs.
|
|
|
|
|
|
|
|
This operation is implemented in terms of zero or more calls to the stream's
|
|
|
|
`async_write_some` function, and is known as a <em>composed operation</em>.
|
|
|
|
The program must ensure that the stream performs no other write operations
|
|
|
|
until this operation completes.
|
|
|
|
|
|
|
|
@param stream The stream to which the data is to be written.
|
|
|
|
The type must support the @b AsyncWriteStream concept.
|
|
|
|
|
|
|
|
@param sr The serializer to use.
|
2017-06-03 09:45:09 -07:00
|
|
|
The object must remain valid at least until the
|
|
|
|
handler is called; ownership is not transferred.
|
2017-05-31 08:01:55 -07:00
|
|
|
|
|
|
|
@param handler The handler to be called when the operation
|
|
|
|
completes. Copies will be made of the handler as required.
|
|
|
|
The equivalent function signature of the handler must be:
|
|
|
|
@code void handler(
|
|
|
|
error_code const& error // result of operation
|
|
|
|
); @endcode
|
|
|
|
Regardless of whether the asynchronous operation completes
|
|
|
|
immediately or not, the handler will not be invoked from within
|
|
|
|
this function. Invocation of the handler will be performed in a
|
|
|
|
manner equivalent to using `boost::asio::io_service::post`.
|
|
|
|
|
|
|
|
@note The implementation will call @ref serializer::split with
|
|
|
|
the value `true` on the serializer passed in.
|
|
|
|
|
|
|
|
@see @ref serializer
|
|
|
|
*/
|
|
|
|
template<class AsyncWriteStream,
|
|
|
|
bool isRequest, class Body, class Fields,
|
2017-06-07 05:10:58 -07:00
|
|
|
class Decorator, class WriteHandler>
|
2017-05-31 08:01:55 -07:00
|
|
|
#if BEAST_DOXYGEN
|
|
|
|
void_or_deduced
|
|
|
|
#else
|
|
|
|
async_return_type<WriteHandler, void(error_code)>
|
|
|
|
#endif
|
|
|
|
async_write_header(AsyncWriteStream& stream, serializer<
|
2017-06-07 05:10:58 -07:00
|
|
|
isRequest, Body, Fields, Decorator>& sr,
|
2017-05-31 08:01:55 -07:00
|
|
|
WriteHandler&& handler);
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/** Write a complete message to a stream using a serializer.
|
|
|
|
|
|
|
|
This function is used to write a complete message to a stream using
|
|
|
|
a caller-provided HTTP/1 serializer. The call will block until one
|
|
|
|
of the following conditions is true:
|
|
|
|
|
|
|
|
@li The function @ref serializer::is_done returns `true`
|
2016-05-01 12:33:35 -04:00
|
|
|
|
|
|
|
@li An error occurs.
|
|
|
|
|
|
|
|
This operation is implemented in terms of one or more calls
|
|
|
|
to the stream's `write_some` function.
|
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
@param stream The stream to which the data is to be written.
|
|
|
|
The type must support the @b SyncWriteStream concept.
|
|
|
|
|
|
|
|
@param sr The serializer to use.
|
|
|
|
|
|
|
|
@throws system_error Thrown on failure.
|
|
|
|
|
|
|
|
@see @ref serializer
|
|
|
|
*/
|
2017-06-07 05:10:58 -07:00
|
|
|
template<class SyncWriteStream, bool isRequest,
|
|
|
|
class Body, class Fields, class Decorator>
|
2017-05-31 08:01:55 -07:00
|
|
|
void
|
|
|
|
write(SyncWriteStream& stream, serializer<
|
2017-06-07 05:10:58 -07:00
|
|
|
isRequest, Body, Fields, Decorator>& sr);
|
2017-05-31 08:01:55 -07:00
|
|
|
|
|
|
|
/** Write a complete message to a stream using a serializer.
|
|
|
|
|
|
|
|
This function is used to write a complete message to a stream using
|
|
|
|
a caller-provided HTTP/1 serializer. The call will block until one
|
|
|
|
of the following conditions is true:
|
|
|
|
|
|
|
|
@li The function @ref serializer::is_done returns `true`
|
|
|
|
|
|
|
|
@li An error occurs.
|
|
|
|
|
|
|
|
This operation is implemented in terms of one or more calls
|
|
|
|
to the stream's `write_some` function.
|
|
|
|
|
|
|
|
@param stream The stream to which the data is to be written.
|
|
|
|
The type must support the @b SyncWriteStream concept.
|
|
|
|
|
|
|
|
@param sr The serializer to use.
|
|
|
|
|
|
|
|
@param ec Set to the error, if any occurred.
|
|
|
|
|
|
|
|
@see @ref serializer
|
|
|
|
*/
|
2017-06-07 05:10:58 -07:00
|
|
|
template<class SyncWriteStream, bool isRequest,
|
|
|
|
class Body, class Fields, class Decorator>
|
2017-05-31 08:01:55 -07:00
|
|
|
void
|
|
|
|
write(SyncWriteStream& stream, serializer<
|
2017-06-07 05:10:58 -07:00
|
|
|
isRequest, Body, Fields, Decorator>& sr,
|
2017-05-31 08:01:55 -07:00
|
|
|
error_code& ec);
|
|
|
|
|
|
|
|
/** Write a complete message to a stream asynchronously using a serializer.
|
|
|
|
|
|
|
|
This function is used to write a complete message to a stream
|
|
|
|
asynchronously using a caller-provided HTTP/1 serializer. The
|
|
|
|
function call always returns immediately. The asynchronous
|
|
|
|
operation will continue until one of the following conditions is true:
|
|
|
|
|
|
|
|
@li The function @ref serializer::is_done returns `true`
|
|
|
|
|
|
|
|
@li An error occurs.
|
|
|
|
|
|
|
|
This operation is implemented in terms of zero or more calls to the stream's
|
|
|
|
`async_write_some` function, and is known as a <em>composed operation</em>.
|
|
|
|
The program must ensure that the stream performs no other write operations
|
|
|
|
until this operation completes.
|
|
|
|
|
|
|
|
@param stream The stream to which the data is to be written.
|
|
|
|
The type must support the @b AsyncWriteStream concept.
|
|
|
|
|
|
|
|
@param sr The serializer to use.
|
2017-06-03 09:45:09 -07:00
|
|
|
The object must remain valid at least until the
|
|
|
|
handler is called; ownership is not transferred.
|
2017-05-31 08:01:55 -07:00
|
|
|
|
|
|
|
@param handler The handler to be called when the operation
|
|
|
|
completes. Copies will be made of the handler as required.
|
|
|
|
The equivalent function signature of the handler must be:
|
|
|
|
@code void handler(
|
|
|
|
error_code const& error // result of operation
|
|
|
|
); @endcode
|
|
|
|
Regardless of whether the asynchronous operation completes
|
|
|
|
immediately or not, the handler will not be invoked from within
|
|
|
|
this function. Invocation of the handler will be performed in a
|
|
|
|
manner equivalent to using `boost::asio::io_service::post`.
|
|
|
|
|
|
|
|
@see @ref serializer
|
|
|
|
*/
|
|
|
|
template<class AsyncWriteStream,
|
|
|
|
bool isRequest, class Body, class Fields,
|
2017-06-07 05:10:58 -07:00
|
|
|
class Decorator, class WriteHandler>
|
2017-05-31 08:01:55 -07:00
|
|
|
#if BEAST_DOXYGEN
|
|
|
|
void_or_deduced
|
|
|
|
#else
|
|
|
|
async_return_type<WriteHandler, void(error_code)>
|
|
|
|
#endif
|
|
|
|
async_write(AsyncWriteStream& stream, serializer<
|
2017-06-07 05:10:58 -07:00
|
|
|
isRequest, Body, Fields, Decorator>& sr,
|
2017-05-31 08:01:55 -07:00
|
|
|
WriteHandler&& handler);
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/** Write a complete message to a stream.
|
|
|
|
|
|
|
|
This function is used to write a complete message to a stream using
|
|
|
|
HTTP/1. The call will block until one of the following conditions is true:
|
|
|
|
|
|
|
|
@li The entire message is written.
|
|
|
|
|
|
|
|
@li An error occurs.
|
|
|
|
|
|
|
|
This operation is implemented in terms of one or more calls to the stream's
|
|
|
|
`write_some` function. The algorithm will use a temporary @ref serializer
|
|
|
|
with an empty chunk decorator to produce buffers. If the semantics of the
|
|
|
|
message indicate that the connection should be closed after the message is
|
|
|
|
sent, the error delivered by this function will be @ref error::end_of_stream
|
2016-05-01 12:33:35 -04:00
|
|
|
|
|
|
|
@param stream The stream to which the data is to be written.
|
2017-05-10 12:03:00 -07:00
|
|
|
The type must support the @b SyncWriteStream concept.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2016-05-01 12:33:35 -04:00
|
|
|
@param msg The message to write.
|
|
|
|
|
2016-10-04 18:00:11 -04:00
|
|
|
@throws system_error Thrown on failure.
|
2017-05-31 08:01:55 -07:00
|
|
|
|
|
|
|
@see @ref message
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
|
|
|
template<class SyncWriteStream,
|
2016-11-10 05:34:49 -05:00
|
|
|
bool isRequest, class Body, class Fields>
|
2017-07-20 08:01:46 -07:00
|
|
|
void
|
|
|
|
write(SyncWriteStream& stream,
|
2016-11-10 05:34:49 -05:00
|
|
|
message<isRequest, Body, Fields> const& msg);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
/** Write a complete message to a stream.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
This function is used to write a complete message to a stream using
|
|
|
|
HTTP/1. The call will block until one of the following conditions is true:
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2016-11-10 05:34:49 -05:00
|
|
|
@li The entire message is written.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
|
|
|
@li An error occurs.
|
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
This operation is implemented in terms of one or more calls to the stream's
|
|
|
|
`write_some` function. The algorithm will use a temporary @ref serializer
|
|
|
|
with an empty chunk decorator to produce buffers. If the semantics of the
|
|
|
|
message indicate that the connection should be closed after the message is
|
|
|
|
sent, the error delivered by this function will be @ref error::end_of_stream
|
2016-05-01 12:33:35 -04:00
|
|
|
|
|
|
|
@param stream The stream to which the data is to be written.
|
2017-05-10 12:03:00 -07:00
|
|
|
The type must support the @b SyncWriteStream concept.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
|
|
|
@param msg The message to write.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
@param ec Set to the error, if any occurred.
|
2017-05-31 08:01:55 -07:00
|
|
|
|
|
|
|
@see @ref message
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
|
|
|
template<class SyncWriteStream,
|
2016-11-10 05:34:49 -05:00
|
|
|
bool isRequest, class Body, class Fields>
|
2017-07-20 08:01:46 -07:00
|
|
|
void
|
|
|
|
write(SyncWriteStream& stream,
|
2016-11-10 05:34:49 -05:00
|
|
|
message<isRequest, Body, Fields> const& msg,
|
2017-07-20 08:01:46 -07:00
|
|
|
error_code& ec);
|
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
/** Write a complete message to a stream asynchronously.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
This function is used to write a complete message to a stream asynchronously
|
|
|
|
using HTTP/1. The function call always returns immediately. The asynchronous
|
|
|
|
operation will continue until one of the following conditions is true:
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2016-11-10 05:34:49 -05:00
|
|
|
@li The entire message is written.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
|
|
|
@li An error occurs.
|
|
|
|
|
2017-05-31 08:01:55 -07:00
|
|
|
This operation is implemented in terms of zero or more calls to the stream's
|
|
|
|
`async_write_some` function, and is known as a <em>composed operation</em>.
|
|
|
|
The program must ensure that the stream performs no other write operations
|
|
|
|
until this operation completes. The algorithm will use a temporary
|
|
|
|
@ref serializer with an empty chunk decorator to produce buffers. If
|
|
|
|
the semantics of the message indicate that the connection should be
|
|
|
|
closed after the message is sent, the error delivered by this function
|
|
|
|
will be @ref error::end_of_stream
|
2016-05-01 12:33:35 -04:00
|
|
|
|
|
|
|
@param stream The stream to which the data is to be written.
|
2017-05-10 12:03:00 -07:00
|
|
|
The type must support the @b AsyncWriteStream concept.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-06-03 09:45:09 -07:00
|
|
|
@param msg The message to write.
|
|
|
|
The object must remain valid at least until the
|
|
|
|
handler is called; ownership is not transferred.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2016-11-10 05:34:49 -05:00
|
|
|
@param handler The handler to be called when the operation
|
|
|
|
completes. Copies will be made of the handler as required.
|
|
|
|
The equivalent function signature of the handler must be:
|
2017-07-20 08:01:46 -07:00
|
|
|
@code void handler(
|
|
|
|
error_code const& error // result of operation
|
|
|
|
); @endcode
|
|
|
|
Regardless of whether the asynchronous operation completes
|
|
|
|
immediately or not, the handler will not be invoked from within
|
|
|
|
this function. Invocation of the handler will be performed in a
|
2016-05-01 12:33:35 -04:00
|
|
|
manner equivalent to using `boost::asio::io_service::post`.
|
2017-05-31 08:01:55 -07:00
|
|
|
|
|
|
|
@see @ref message
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
|
|
|
template<class AsyncWriteStream,
|
2016-11-10 05:34:49 -05:00
|
|
|
bool isRequest, class Body, class Fields,
|
2017-07-20 08:01:46 -07:00
|
|
|
class WriteHandler>
|
2017-05-12 17:13:03 -07:00
|
|
|
async_return_type<
|
|
|
|
WriteHandler, void(error_code)>
|
2017-07-20 08:01:46 -07:00
|
|
|
async_write(AsyncWriteStream& stream,
|
2017-06-21 11:50:50 -07:00
|
|
|
message<isRequest, Body, Fields>& msg,
|
2017-07-20 08:01:46 -07:00
|
|
|
WriteHandler&& handler);
|
|
|
|
|
2016-11-07 12:20:39 -05:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2017-05-28 19:49:41 -07:00
|
|
|
/** Serialize an HTTP/1 header to a `std::ostream`.
|
2016-11-07 12:20:39 -05:00
|
|
|
|
2016-11-10 05:34:49 -05:00
|
|
|
The function converts the header to its HTTP/1 serialized
|
|
|
|
representation and stores the result in the output stream.
|
2016-11-07 12:20:39 -05:00
|
|
|
|
|
|
|
@param os The output stream to write to.
|
|
|
|
|
2016-11-10 05:34:49 -05:00
|
|
|
@param msg The message fields to write.
|
2016-11-07 12:20:39 -05:00
|
|
|
*/
|
2016-11-10 05:34:49 -05:00
|
|
|
template<bool isRequest, class Fields>
|
2016-11-07 12:20:39 -05:00
|
|
|
std::ostream&
|
|
|
|
operator<<(std::ostream& os,
|
2016-11-10 05:34:49 -05:00
|
|
|
header<isRequest, Fields> const& msg);
|
2016-11-07 12:20:39 -05:00
|
|
|
|
2017-05-28 19:49:41 -07:00
|
|
|
/** Serialize an HTTP/1 message to a `std::ostream`.
|
2016-04-29 06:04:40 -04:00
|
|
|
|
2016-05-01 11:14:10 -04:00
|
|
|
The function converts the message to its HTTP/1 serialized
|
2016-04-29 06:04:40 -04:00
|
|
|
representation and stores the result in the output stream.
|
|
|
|
|
2016-05-01 12:33:35 -04:00
|
|
|
The implementation will automatically perform chunk encoding if
|
|
|
|
the contents of the message indicate that chunk encoding is required.
|
|
|
|
|
2016-11-07 12:20:39 -05:00
|
|
|
@param os The output stream to write to.
|
2016-04-29 06:04:40 -04:00
|
|
|
|
|
|
|
@param msg The message to write.
|
|
|
|
*/
|
2016-11-10 05:34:49 -05:00
|
|
|
template<bool isRequest, class Body, class Fields>
|
2016-04-29 06:04:40 -04:00
|
|
|
std::ostream&
|
|
|
|
operator<<(std::ostream& os,
|
2016-11-10 05:34:49 -05:00
|
|
|
message<isRequest, Body, Fields> const& msg);
|
2016-04-29 06:04:40 -04:00
|
|
|
|
2017-07-20 08:01:46 -07:00
|
|
|
} // http
|
|
|
|
} // beast
|
|
|
|
|
|
|
|
#include <beast/http/impl/write.ipp>
|
|
|
|
|
|
|
|
#endif
|