Tidy up tests, build scripts, and documentation:

* Concepts split up into individual files
* Function definitions moved to .ipp files
* Add more tests to fill gaps in coverage
* Fix documentation Xsl
This commit is contained in:
Vinnie Falco committed 2017-07-20 08:12:06 -07:00
1 parent c309f53ed2
commit 313620ce7e
92 files changed
+2915 -1808

No files matched your search

+13 -3
View File
@@ -8,7 +8,6 @@
#ifndef BEAST_HTTP_BASIC_HEADERS_HPP
#define BEAST_HTTP_BASIC_HEADERS_HPP
#include <beast/type_check.hpp>
#include <beast/detail/ci_char_traits.hpp>
#include <beast/detail/empty_base_optimization.hpp>
#include <boost/intrusive/list.hpp>
@@ -237,9 +236,20 @@ public:
//------------------------------------------------------------------------------
/** Container to store HTTP headers.
/** A container for storing HTTP headers.
Meets the requirements of `FieldSequence`.
This container is designed to store the field value pairs that make
up the headers and trailers in a HTTP message. Objects of this type
are iterable, which each element holding the field name and field
value.
Field names are stored as-is, but comparison are case-insensitive.
The container preserves the order of insertion of fields with
different names. For fields with the same name, the implementation
concatenates values inserted with duplicate names as per the
rules in rfc2616 section 4.2.
@note Meets the requirements of @b `FieldSequence`.
*/
template<class Allocator>
class basic_headers
+21 -21
View File
@@ -12,7 +12,6 @@
#include <beast/http/parse_error.hpp>
#include <beast/http/rfc7230.hpp>
#include <beast/http/detail/basic_parser_v1.hpp>
#include <beast/type_check.hpp>
#include <boost/asio/buffer.hpp>
#include <array>
#include <cassert>
@@ -43,49 +42,49 @@ enum values
if those members are present (detected through SFINAE). The
signatures which can be present in the derived class are:<br>
@li `void on_method(boost::string_ref const&, error_code& ec)`
@li `void on_method(boost::string_ref const&, error_code&)`
Called for each piece of the Request-Method
@li `void on_uri(boost::string_ref const&, error_code& ec)`
@li `void on_uri(boost::string_ref const&, error_code&)`
Called for each piece of the Request-URI
@li `void on_reason(boost::string_ref const&, error_code& ec)`
@li `void on_reason(boost::string_ref const&, error_code&)`
Called for each piece of the reason-phrase
@li `void on_request(error_code& ec)`
@li `void on_request(error_code&)`
Called after the entire Request-Line has been parsed successfully.
@li `void on_response(error_code& ec)`
@li `void on_response(error_code&)`
Called after the entire Response-Line has been parsed successfully.
@li `void on_field(boost::string_ref const&, error_code& ec)`
@li `void on_field(boost::string_ref const&, error_code&)`
Called for each piece of the current header field.
@li `void on_value(boost::string_ref const&, error_code& ec)`
@li `void on_value(boost::string_ref const&, error_code&)`
Called for each piece of the current header value.
@li `int on_headers(error_code& ec)`
@li `int on_headers(error_code&)`
Called when all the headers have been parsed successfully.
@li `void on_body(boost::string_ref const&, error_code& ec)`
@li `void on_body(boost::string_ref const&, error_code&)`
Called for each piece of the body. If the headers indicated
chunked encoding, the chunk encoding is removed from the
buffer before being passed to the callback.
@li `void on_complete(error_code& ec)`
@li `void on_complete(error_code&)`
Called when the entire message has been parsed successfully.
At this point, basic_parser_v1::complete() returns `true`, and
the parser is ready to parse another message if keep_alive()
At this point, @ref basic_parser_v1::complete returns `true`, and
the parser is ready to parse another message if keep_alive
would return `true`.
The return value of `on_headers` is special, it controls whether
@@ -101,7 +100,7 @@ enum values
The parser uses traits to determine if the callback is possible.
If the Derived type omits one or more callbacks, they are simply
skipped with no compilation error. The default behavior of on_body
skipped with no compilation error. The default behavior of `on_body`
when the derived class does not provide the member, is to specify that
the body should not be skipped.
@@ -354,12 +353,15 @@ public:
@return The number of bytes consumed in the input sequence.
*/
template<class ConstBufferSequence,
class = typename std::enable_if<
! std::is_convertible<ConstBufferSequence,
boost::asio::const_buffer>::value>::type
>
template<class ConstBufferSequence>
#if GENERATING_DOCS
std::size_t
#else
typename std::enable_if<
! std::is_convertible<ConstBufferSequence,
boost::asio::const_buffer>::value,
std::size_t>::type
#endif
write(ConstBufferSequence const& buffers, error_code& ec);
/** Write a single buffer of data to the parser.
@@ -380,8 +382,6 @@ public:
Callbacks and errors will still be processed as usual.
@note This is typically called when a socket read returns eof.
@throws boost::system::system_error Thrown on failure.
*/
void
write_eof(error_code& ec);
@@ -5,11 +5,11 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BEAST_HTTP_BODY_WRITER_HPP
#define BEAST_HTTP_BODY_WRITER_HPP
#ifndef BEAST_HTTP_BODY_TYPE_HPP
#define BEAST_HTTP_BODY_TYPE_HPP
// Convenience header to include everything necessary for
// declaring an object meeting the BodyWriter requirements.
// Convenience header to include everything
// needed when declarating a user defined Body type.
#include <beast/http/error.hpp>
#include <beast/http/message.hpp>
+3 -1
View File
@@ -8,7 +8,7 @@
#ifndef BEAST_HTTP_EMPTY_BODY_HPP
#define BEAST_HTTP_EMPTY_BODY_HPP
#include <beast/http/body_writer.hpp>
#include <beast/http/body_type.hpp>
#include <beast/streambuf.hpp>
#include <boost/asio/buffer.hpp>
#include <memory>
@@ -18,6 +18,8 @@ namespace beast {
namespace http {
/** An empty content-body.
Meets the requirements of @b `Body`.
*/
struct empty_body
{
+1
View File
@@ -9,6 +9,7 @@
#define BEAST_HTTP_ERROR_HPP
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
namespace beast {
namespace http {
@@ -8,8 +8,6 @@
#ifndef BEAST_HTTP_IMPL_BASIC_HEADERS_IPP
#define BEAST_HTTP_IMPL_BASIC_HEADERS_IPP
#include <beast/type_check.hpp>
namespace beast {
namespace http {
+7 -2
View File
@@ -8,6 +8,8 @@
#ifndef BEAST_HTTP_IMPL_BASIC_PARSER_V1_IPP
#define BEAST_HTTP_IMPL_BASIC_PARSER_V1_IPP
#include <beast/buffer_concepts.hpp>
namespace beast {
namespace http {
@@ -32,8 +34,11 @@ keep_alive() const
// Implementation inspired by nodejs/http-parser
template<bool isRequest, class Derived>
template<class ConstBufferSequence, class>
std::size_t
template<class ConstBufferSequence>
typename std::enable_if<
! std::is_convertible<ConstBufferSequence,
boost::asio::const_buffer>::value,
std::size_t>::type
basic_parser_v1<isRequest, Derived>::
write(ConstBufferSequence const& buffers, error_code& ec)
{
-1
View File
@@ -10,7 +10,6 @@
#include <beast/http/rfc2616.hpp>
#include <beast/http/detail/has_content_length.hpp>
#include <beast/type_check.hpp>
#include <boost/optional.hpp>
#include <stdexcept>
+1
View File
@@ -11,6 +11,7 @@
#include <beast/http/parser_v1.hpp>
#include <beast/bind_handler.hpp>
#include <beast/handler_alloc.hpp>
#include <beast/stream_concepts.hpp>
#include <cassert>
namespace beast {
+2 -1
View File
@@ -13,9 +13,10 @@
#include <beast/http/detail/has_content_length.hpp>
#include <beast/buffer_cat.hpp>
#include <beast/bind_handler.hpp>
#include <beast/buffer_concepts.hpp>
#include <beast/handler_alloc.hpp>
#include <beast/stream_concepts.hpp>
#include <beast/streambuf.hpp>
#include <beast/type_check.hpp>
#include <beast/write_streambuf.hpp>
#include <boost/asio/write.hpp>
#include <boost/logic/tribool.hpp>
-1
View File
@@ -9,7 +9,6 @@
#define BEAST_HTTP_MESSAGE_HPP
#include <beast/http/basic_headers.hpp>
#include <beast/type_check.hpp>
#include <memory>
#include <string>
+1 -2
View File
@@ -9,7 +9,6 @@
#define BEAST_HTTP_MESSAGE_V1_HPP
#include <beast/http/message.hpp>
#include <beast/type_check.hpp>
#include <memory>
#include <string>
@@ -92,7 +91,7 @@ is_upgrade(message_v1<isRequest, Body, Headers> const& msg);
/** HTTP/1 connection prepare options.
@note These values are used with `prepare`.
@note These values are used with @ref prepare.
*/
enum class connection
{
+58 -20
View File
@@ -19,17 +19,29 @@ namespace http {
/** Read a HTTP/1 message from a stream.
@param stream The stream to read the message from.
This function is used to synchronously read a message from
the stream. The call blocks until one of the following conditions
is true:
@param streambuf A Streambuf used to hold unread bytes. The
implementation may read past the end of the message. The extra
bytes are stored here, to be presented in a subsequent call to
read.
@li A complete message is read in.
@param msg An object used to store the read message. Any
@li An error occurs on the stream.
This function is implemented in terms of one or more calls to the
stream's `read_some` function.
@param stream The stream to which the data is to be written.
The type must support the @b `SyncReadStream` concept.
@param streambuf An object meeting the @b `Streambuf` type requirements
used to hold unread bytes. The implementation may read past the end of
the message. The extra bytes are stored here, to be presented in a
subsequent call to @ref read.
@param msg An object used to store the message. Any
contents will be overwritten.
@throws boost::system::system_error on failure.
@throws boost::system::system_error Thrown on failure.
*/
template<class SyncReadStream, class Streambuf,
bool isRequest, class Body, class Headers>
@@ -43,17 +55,29 @@ read(SyncReadStream& stream, Streambuf& streambuf,
throw boost::system::system_error{ec};
}
/** Read a HTTP message from a stream.
/** Read a HTTP/1 message from a stream.
@param stream The stream to read the message from.
This function is used to synchronously read a message from
the stream. The call blocks until one of the following conditions
is true:
@param streambuf A Streambuf used to hold unread bytes. The
implementation may read past the end of the message. The extra
bytes are stored here, to be presented in a subsequent call to
read.
@li A complete message is read in.
@param msg An object used to store the read message. Any
contents will be overwritten.
@li An error occurs on the stream.
This function is implemented in terms of one or more calls to the
stream's `read_some` function.
@param stream The stream to which the data is to be written.
The type must support the @b `SyncReadStream` concept.
@param streambuf An object meeting the @b `Streambuf` type requirements
used to hold unread bytes. The implementation may read past the end of
the message. The extra bytes are stored here, to be presented in a
subsequent call to @ref read.
@param msg An object used to store the message. Any contents
will be overwritten.
@param ec Set to the error, if any occurred.
*/
@@ -64,17 +88,31 @@ read(SyncReadStream& stream, Streambuf& streambuf,
message_v1<isRequest, Body, Headers>& msg,
error_code& ec);
/** Start reading a HTTP message from a stream asynchronously.
/** Start an asynchronous operation to read a HTTP/1 message from a stream.
This function is used to asynchronously read a message from the
stream. The function call always returns immediately. The asynchronous
operation will continue until one of the following conditions is true:
@li A complete message is read in.
@li An error occurs on the stream.
This operation is implemented in terms of one or more calls to the
next layer's `async_read_some` function, and is known as a
<em>composed operation</em>. The program must ensure that the stream
performs no other operations until this operation completes.
@param stream The stream to read the message from.
The type must support the @b `AsyncReadStream` concept.
@param streambuf A Streambuf used to hold unread bytes. The
implementation may read past the end of the message. The extra
bytes are stored here, to be presented in a subsequent call to
async_read.
@ref async_read.
@param msg An object used to store the read message. Any
contents will be overwritten.
@param msg An object used to store the message. Any contents
will be overwritten.
@param handler The handler to be called when the request completes.
Copies will be made of the handler as required. The equivalent
@@ -85,7 +123,7 @@ read(SyncReadStream& stream, Streambuf& streambuf,
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().
manner equivalent to using `boost::asio::io_service::post`.
*/
template<class AsyncReadStream, class Streambuf,
bool isRequest, class Body, class Headers,
+6 -4
View File
@@ -8,7 +8,7 @@
#ifndef BEAST_HTTP_STREAMBUF_BODY_HPP
#define BEAST_HTTP_STREAMBUF_BODY_HPP
#include <beast/http/body_writer.hpp>
#include <beast/http/body_type.hpp>
#include <beast/buffer_cat.hpp>
#include <beast/streambuf.hpp>
#include <memory>
@@ -17,7 +17,9 @@
namespace beast {
namespace http {
/** A Body represented by a Streambuf
/** A message body represented by a Streambuf
Meets the requirements of @b `Body`.
*/
template<class Streambuf>
struct basic_streambuf_body
@@ -34,10 +36,10 @@ private:
value_type& sb_;
public:
template<bool isRequest, class Allocator>
template<bool isRequest, class Headers>
explicit
reader(message<isRequest,
basic_streambuf_body, Allocator>& m) noexcept
basic_streambuf_body, Headers>& m) noexcept
: sb_(m.body)
{
}
+5 -3
View File
@@ -8,7 +8,7 @@
#ifndef BEAST_HTTP_STRING_BODY_HPP
#define BEAST_HTTP_STRING_BODY_HPP
#include <beast/http/body_writer.hpp>
#include <beast/http/body_type.hpp>
#include <beast/buffer_cat.hpp>
#include <beast/streambuf.hpp>
#include <memory>
@@ -18,6 +18,8 @@ namespace beast {
namespace http {
/** A Body represented by a std::string.
Meets the requirements of @b `Body`.
*/
struct string_body
{
@@ -33,10 +35,10 @@ private:
value_type& s_;
public:
template<bool isRequest, class Allocator>
template<bool isRequest, class Headers>
explicit
reader(message<isRequest,
string_body, Allocator>& m) noexcept
string_body, Headers>& m) noexcept
: s_(m.body)
{
}
+71 -12
View File
@@ -18,13 +18,30 @@
namespace beast {
namespace http {
/** Write a HTTP/1 message to a stream.
/** Write a HTTP/1 message on a stream.
@param stream The stream to send the message on.
This function is used to write a message to a stream. The call
will block until one of the following conditions is true:
@param msg The message to send.
@li The entire message is sent.
@throws boost::system::error code on failure.
@li An error occurs.
This operation is implemented in terms of one or more calls
to the stream's `write_some` function.
The implementation will automatically perform chunk encoding if
the contents of the message indicate that chunk encoding is required.
If the semantics of the message indicate that the connection should
be closed after the message is sent, the error returns from this
function will be `boost::asio::error::eof`.
@param stream The stream to which the data is to be written.
The type must support the @b `SyncWriteStream` concept.
@param msg The message to write.
@throws boost::system::error Thrown on failure.
*/
template<class SyncWriteStream,
bool isRequest, class Body, class Headers>
@@ -32,11 +49,28 @@ void
write(SyncWriteStream& stream,
message_v1<isRequest, Body, Headers> const& msg);
/** Write a HTTP/1 message to a stream.
/** Write a HTTP/1 message on a stream.
@param stream The stream to send the message on.
This function is used to write a message to a stream. The call
will block until one of the following conditions is true:
@param msg The message to send.
@li The entire message is sent.
@li An error occurs.
This operation is implemented in terms of one or more calls
to the stream's `write_some` function.
The implementation will automatically perform chunk encoding if
the contents of the message indicate that chunk encoding is required.
If the semantics of the message indicate that the connection should
be closed after the message is sent, the error returns from this
function will be `boost::asio::error::eof`.
@param stream The stream to which the data is to be written.
The type must support the @b `SyncWriteStream` concept.
@param msg The message to write.
@param ec Set to the error, if any occurred.
*/
@@ -47,13 +81,35 @@ write(SyncWriteStream& stream,
message_v1<isRequest, Body, Headers> const& msg,
error_code& ec);
/** Start writing a HTTP/1 message to a stream asynchronously.
/** Start an asynchronous operation to write a HTTP/1 message to a stream.
@param stream The stream to send the message on.
This function is used to asynchronously write a message to a stream.
The function call always returns immediately. The asynchronous
operation will continue until one of the following conditions is true:
@li The entire message is sent.
@li An error occurs.
This operation is implemented in terms of one or more calls to the
stream's `async_write_some` functions, and is known as a <em>composed
operation</em>. The program must ensure that the stream performs no
other write operations (such as @ref async_write, the stream's
`async_write_some` function, or any other composed operations that
perform writes) until this operation completes.
The implementation will automatically perform chunk encoding if
the contents of the message indicate that chunk encoding is required.
If the semantics of the message indicate that the connection should
be closed after the message is sent, the operation will complete with
the error set to `boost::asio::error::eof`.
@param stream The stream to which the data is to be written.
The type must support the @b `AsyncWriteStream` concept.
@param msg The message to send.
@param token The handler to be called when the request completes.
@param handler The handler to be called when the request completes.
Copies will be made of the handler as required. The equivalent
function signature of the handler must be:
@code void handler(
@@ -62,9 +118,9 @@ write(SyncWriteStream& stream,
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().
manner equivalent to using `boost::asio::io_service::post`.
@note The message must remain valid at least until the
@note The message object must remain valid at least until the
completion handler is called, no copies are made.
*/
template<class AsyncWriteStream,
@@ -85,6 +141,9 @@ async_write(AsyncWriteStream& stream,
The function converts the message to its HTTP/1 serialized
representation and stores the result in the output stream.
The implementation will automatically perform chunk encoding if
the contents of the message indicate that chunk encoding is required.
@param os The ostream to write to.
@param msg The message to write.