Refactor HTTP serialization (API Change):

A new class `serializer` is introduced to permit incremental
serialization of HTTP messages. Existing free functions are
re-implemented in terms of this new class.

* The BodyReader concept is refined to support a greater variety
of strategies for providing buffers representing the body to
the serialization algorithms.

* Added buffer_body, a new model of Body which allows the caller
to provide a series of owned buffers using their own serialization
loop.

* Added empty_body, a model of Body which is for serialization only,
to represent HTTP messages with no content body.

* Removed overloads of write and async_write which send only
the HTTP header.

* Removed public interfaces for performing low-level chunk encoding.
This commit is contained in:
Vinnie Falco
2017-07-20 08:12:17 -07:00
parent b9bdb1bbbc
commit 3664329ea7
44 changed files with 2540 additions and 1104 deletions
+19 -11
View File
@@ -9,6 +9,7 @@
#define BEAST_WEBSOCKET_IMPL_ACCEPT_IPP
#include <beast/websocket/detail/type_traits.hpp>
#include <beast/http/empty_body.hpp>
#include <beast/http/message.hpp>
#include <beast/http/header_parser.hpp>
#include <beast/http/read.hpp>
@@ -39,7 +40,8 @@ class stream<NextLayer>::response_op
{
bool cont;
stream<NextLayer>& ws;
http::header<false, http::fields> res;
http::message<false,
http::empty_body, http::fields> res;
int state = 0;
template<class Fields, class Decorator>
@@ -188,8 +190,8 @@ class stream<NextLayer>::accept_op
template<class Buffers>
data(Handler& handler, stream<NextLayer>& ws_,
Buffers const& buffers,
Decorator const& decorator_)
Buffers const& buffers,
Decorator const& decorator_)
: ws(ws_)
, decorator(decorator_)
{
@@ -365,7 +367,8 @@ accept_ex(ResponseDecorator const& decorator, error_code& ec)
template<class NextLayer>
template<class ConstBufferSequence>
void
typename std::enable_if<! http::detail::is_header<
ConstBufferSequence>::value>::type
stream<NextLayer>::
accept(ConstBufferSequence const& buffers)
{
@@ -383,7 +386,8 @@ accept(ConstBufferSequence const& buffers)
template<class NextLayer>
template<
class ConstBufferSequence, class ResponseDecorator>
void
typename std::enable_if<! http::detail::is_header<
ConstBufferSequence>::value>::type
stream<NextLayer>::
accept_ex(ConstBufferSequence const& buffers,
ResponseDecorator const &decorator)
@@ -404,7 +408,8 @@ accept_ex(ConstBufferSequence const& buffers,
template<class NextLayer>
template<class ConstBufferSequence>
void
typename std::enable_if<! http::detail::is_header<
ConstBufferSequence>::value>::type
stream<NextLayer>::
accept(ConstBufferSequence const& buffers, error_code& ec)
{
@@ -425,7 +430,8 @@ accept(ConstBufferSequence const& buffers, error_code& ec)
template<class NextLayer>
template<
class ConstBufferSequence, class ResponseDecorator>
void
typename std::enable_if<! http::detail::is_header<
ConstBufferSequence>::value>::type
stream<NextLayer>::
accept_ex(ConstBufferSequence const& buffers,
ResponseDecorator const& decorator, error_code& ec)
@@ -641,8 +647,9 @@ async_accept_ex(ResponseDecorator const& decorator,
template<class NextLayer>
template<class ConstBufferSequence, class AcceptHandler>
async_return_type<
AcceptHandler, void(error_code)>
typename std::enable_if<
! http::detail::is_header<ConstBufferSequence>::value,
async_return_type<AcceptHandler, void(error_code)>>::type
stream<NextLayer>::
async_accept(ConstBufferSequence const& buffers,
AcceptHandler&& handler)
@@ -664,8 +671,9 @@ async_accept(ConstBufferSequence const& buffers,
template<class NextLayer>
template<class ConstBufferSequence,
class ResponseDecorator, class AcceptHandler>
async_return_type<
AcceptHandler, void(error_code)>
typename std::enable_if<
! http::detail::is_header<ConstBufferSequence>::value,
async_return_type<AcceptHandler, void(error_code)>>::type
stream<NextLayer>::
async_accept_ex(ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
+3 -1
View File
@@ -9,6 +9,7 @@
#define BEAST_WEBSOCKET_IMPL_HANDSHAKE_IPP
#include <beast/websocket/detail/type_traits.hpp>
#include <beast/http/empty_body.hpp>
#include <beast/http/message.hpp>
#include <beast/http/read.hpp>
#include <beast/http/write.hpp>
@@ -38,7 +39,8 @@ class stream<NextLayer>::handshake_op
stream<NextLayer>& ws;
response_type* res_p;
detail::sec_ws_key_type key;
request_type req;
http::message<true,
http::empty_body, http::fields> req;
response_type res;
int state = 0;
+2 -2
View File
@@ -196,10 +196,10 @@ build_request(detail::sec_ws_key_type& key,
}
template<class NextLayer>
template<class Decorator>
template<class Fields, class Decorator>
response_type
stream<NextLayer>::
build_response(request_type const& req,
build_response(http::header<true, Fields> const& req,
Decorator const& decorator)
{
auto const decorate =