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 committed 2017-07-20 08:12:17 -07:00
1 parent b9bdb1bbbc
commit 3664329ea7
44 files changed
+2540 -1104

No files matched your search

+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 =
+33 -9
View File
@@ -12,8 +12,10 @@
#include <beast/websocket/option.hpp>
#include <beast/websocket/detail/hybi13.hpp>
#include <beast/websocket/detail/stream_base.hpp>
#include <beast/http/empty_body.hpp>
#include <beast/http/message.hpp>
#include <beast/http/string_body.hpp>
#include <beast/http/detail/type_traits.hpp>
#include <beast/core/async_result.hpp>
#include <beast/core/buffered_read_stream.hpp>
#include <beast/core/string_view.hpp>
@@ -28,12 +30,12 @@ namespace beast {
namespace websocket {
/// The type of object holding HTTP Upgrade requests
using request_type = http::header<true, http::fields>;
using request_type =
http::message<true, http::empty_body, http::fields>;
/// The type of object holding HTTP Upgrade responses
using response_type =
//http::response_header;
http::response<http::string_body, http::fields>;
http::message<false, http::string_body, http::fields>;
/** Information about a WebSocket frame.
@@ -473,7 +475,12 @@ public:
@throws system_error Thrown on failure.
*/
template<class ConstBufferSequence>
#if BEAST_DOXYGEN
void
#else
typename std::enable_if<! http::detail::is_header<
ConstBufferSequence>::value>::type
#endif
accept(ConstBufferSequence const& buffers);
/** Read and respond to a WebSocket HTTP Upgrade request.
@@ -516,7 +523,12 @@ public:
*/
template<class ConstBufferSequence,
class ResponseDecorator>
#if BEAST_DOXYGEN
void
#else
typename std::enable_if<! http::detail::is_header<
ConstBufferSequence>::value>::type
#endif
accept_ex(ConstBufferSequence const& buffers,
ResponseDecorator const& decorator);
@@ -550,7 +562,12 @@ public:
@param ec Set to indicate what error occurred, if any.
*/
template<class ConstBufferSequence>
#if BEAST_DOXYGEN
void
#else
typename std::enable_if<! http::detail::is_header<
ConstBufferSequence>::value>::type
#endif
accept(ConstBufferSequence const& buffers, error_code& ec);
/** Read and respond to a WebSocket HTTP Upgrade request.
@@ -593,7 +610,12 @@ public:
*/
template<class ConstBufferSequence,
class ResponseDecorator>
#if BEAST_DOXYGEN
void
#else
typename std::enable_if<! http::detail::is_header<
ConstBufferSequence>::value>::type
#endif
accept_ex(ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
error_code& ec);
@@ -1085,8 +1107,9 @@ public:
#if BEAST_DOXYGEN
void_or_deduced
#else
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
#endif
async_accept(ConstBufferSequence const& buffers,
AcceptHandler&& handler);
@@ -1153,8 +1176,9 @@ public:
#if BEAST_DOXYGEN
void_or_deduced
#else
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
#endif
async_accept_ex(ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
@@ -2975,9 +2999,9 @@ private:
string_view const& target,
Decorator const& decorator);
template<class Decorator>
template<class Fields, class Decorator>
response_type
build_response(request_type const& req,
build_response(http::header<true, Fields> const& req,
Decorator const& decorator);
void