accept requires a message

This commit is contained in:
Vinnie Falco
2017-07-14 13:00:09 -07:00
parent efd715e55c
commit 3c2d3181fc
5 changed files with 122 additions and 106 deletions

View File

@@ -6,6 +6,7 @@ WebSocket
* stream tidying * stream tidying
* Add rd_close_ to websocket stream state * Add rd_close_ to websocket stream state
* stream uses flat_buffer * stream uses flat_buffer
* accept requires a message
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@@ -42,24 +42,22 @@ class stream<NextLayer>::response_op
response_type res; response_type res;
int state = 0; int state = 0;
template<class Allocator, class Decorator> template<class Body, class Allocator, class Decorator>
data(Handler&, stream<NextLayer>& ws_, http::header< data(Handler&, stream<NextLayer>& ws_, http::request<
true, http::basic_fields<Allocator>> const& req, Body, http::basic_fields<Allocator>> const& req,
Decorator const& decorator, Decorator const& decorator, bool cont_)
bool cont_)
: cont(cont_) : cont(cont_)
, ws(ws_) , ws(ws_)
, res(ws_.build_response(req, decorator)) , res(ws_.build_response(req, decorator))
{ {
} }
template<class Allocator, template<class Body, class Allocator,
class Buffers, class Decorator> class Buffers, class Decorator>
data(Handler&, stream<NextLayer>& ws_, http::header< data(Handler&, stream<NextLayer>& ws_, http::request<
true, http::basic_fields<Allocator>> const& req, Body, http::basic_fields<Allocator>> const& req,
Buffers const& buffers, Buffers const& buffers, Decorator const& decorator,
Decorator const& decorator, bool cont_)
bool cont_)
: cont(cont_) : cont(cont_)
, ws(ws_) , ws(ws_)
, res(ws_.build_response(req, decorator)) , res(ws_.build_response(req, decorator))
@@ -443,10 +441,10 @@ accept_ex(ConstBufferSequence const& buffers,
} }
template<class NextLayer> template<class NextLayer>
template<class Allocator> template<class Body, class Allocator>
void void
stream<NextLayer>:: stream<NextLayer>::
accept(http::header<true, accept(http::request<Body,
http::basic_fields<Allocator>> const& req) http::basic_fields<Allocator>> const& req)
{ {
static_assert(is_sync_stream<next_layer_type>::value, static_assert(is_sync_stream<next_layer_type>::value,
@@ -458,10 +456,11 @@ accept(http::header<true,
} }
template<class NextLayer> template<class NextLayer>
template<class Allocator, class ResponseDecorator> template<class Body,
class Allocator, class ResponseDecorator>
void void
stream<NextLayer>:: stream<NextLayer>::
accept_ex(http::header<true, accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator) ResponseDecorator const& decorator)
{ {
@@ -477,10 +476,10 @@ accept_ex(http::header<true,
} }
template<class NextLayer> template<class NextLayer>
template<class Allocator> template<class Body, class Allocator>
void void
stream<NextLayer>:: stream<NextLayer>::
accept(http::header<true, accept(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
error_code& ec) error_code& ec)
{ {
@@ -491,10 +490,11 @@ accept(http::header<true,
} }
template<class NextLayer> template<class NextLayer>
template<class Allocator, class ResponseDecorator> template<class Body, class Allocator,
class ResponseDecorator>
void void
stream<NextLayer>:: stream<NextLayer>::
accept_ex(http::header<true, accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator, error_code& ec) ResponseDecorator const& decorator, error_code& ec)
{ {
@@ -508,10 +508,11 @@ accept_ex(http::header<true,
} }
template<class NextLayer> template<class NextLayer>
template<class Allocator, class ConstBufferSequence> template<class Body, class Allocator,
class ConstBufferSequence>
void void
stream<NextLayer>:: stream<NextLayer>::
accept(http::header<true, accept(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers) ConstBufferSequence const& buffers)
{ {
@@ -527,11 +528,11 @@ accept(http::header<true,
} }
template<class NextLayer> template<class NextLayer>
template<class Allocator, template<class Body, class Allocator,
class ConstBufferSequence, class ResponseDecorator> class ConstBufferSequence, class ResponseDecorator>
void void
stream<NextLayer>:: stream<NextLayer>::
accept_ex(http::header<true, accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers, ConstBufferSequence const& buffers,
ResponseDecorator const& decorator) ResponseDecorator const& decorator)
@@ -551,11 +552,12 @@ accept_ex(http::header<true,
} }
template<class NextLayer> template<class NextLayer>
template<class Allocator, class ConstBufferSequence> template<class Body, class Allocator,
class ConstBufferSequence>
void void
stream<NextLayer>:: stream<NextLayer>::
accept(http::header<true, accept(http::request<Body,
Allocator> const& req, http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers, error_code& ec) ConstBufferSequence const& buffers, error_code& ec)
{ {
static_assert(is_sync_stream<next_layer_type>::value, static_assert(is_sync_stream<next_layer_type>::value,
@@ -573,11 +575,11 @@ accept(http::header<true,
} }
template<class NextLayer> template<class NextLayer>
template<class Allocator, template<class Body, class Allocator,
class ConstBufferSequence, class ResponseDecorator> class ConstBufferSequence, class ResponseDecorator>
void void
stream<NextLayer>:: stream<NextLayer>::
accept_ex(http::header<true, accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers, ConstBufferSequence const& buffers,
ResponseDecorator const& decorator, ResponseDecorator const& decorator,
@@ -696,11 +698,12 @@ async_accept_ex(ConstBufferSequence const& buffers,
} }
template<class NextLayer> template<class NextLayer>
template<class Allocator, class AcceptHandler> template<class Body, class Allocator,
class AcceptHandler>
async_return_type< async_return_type<
AcceptHandler, void(error_code)> AcceptHandler, void(error_code)>
stream<NextLayer>:: stream<NextLayer>::
async_accept(http::header<true, async_accept(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
AcceptHandler&& handler) AcceptHandler&& handler)
{ {
@@ -719,12 +722,12 @@ async_accept(http::header<true,
} }
template<class NextLayer> template<class NextLayer>
template<class Allocator, template<class Body, class Allocator,
class ResponseDecorator, class AcceptHandler> class ResponseDecorator, class AcceptHandler>
async_return_type< async_return_type<
AcceptHandler, void(error_code)> AcceptHandler, void(error_code)>
stream<NextLayer>:: stream<NextLayer>::
async_accept_ex(http::header<true, async_accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator, AcceptHandler&& handler) ResponseDecorator const& decorator, AcceptHandler&& handler)
{ {
@@ -746,12 +749,12 @@ async_accept_ex(http::header<true,
} }
template<class NextLayer> template<class NextLayer>
template<class Allocator, template<class Body, class Allocator,
class ConstBufferSequence, class AcceptHandler> class ConstBufferSequence, class AcceptHandler>
async_return_type< async_return_type<
AcceptHandler, void(error_code)> AcceptHandler, void(error_code)>
stream<NextLayer>:: stream<NextLayer>::
async_accept(http::header<true, async_accept(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers, ConstBufferSequence const& buffers,
AcceptHandler&& handler) AcceptHandler&& handler)
@@ -774,12 +777,13 @@ async_accept(http::header<true,
} }
template<class NextLayer> template<class NextLayer>
template<class Allocator, class ConstBufferSequence, template<class Body, class Allocator,
class ResponseDecorator, class AcceptHandler> class ConstBufferSequence, class ResponseDecorator,
class AcceptHandler>
async_return_type< async_return_type<
AcceptHandler, void(error_code)> AcceptHandler, void(error_code)>
stream<NextLayer>:: stream<NextLayer>::
async_accept_ex(http::header<true, async_accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers, ConstBufferSequence const& buffers,
ResponseDecorator const& decorator, ResponseDecorator const& decorator,

View File

@@ -501,10 +501,10 @@ build_request(detail::sec_ws_key_type& key,
} }
template<class NextLayer> template<class NextLayer>
template<class Allocator, class Decorator> template<class Body, class Allocator, class Decorator>
response_type response_type
stream<NextLayer>:: stream<NextLayer>::
build_response(http::header<true, build_response(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
Decorator const& decorator) Decorator const& decorator)
{ {
@@ -598,10 +598,11 @@ do_accept(
} }
template<class NextLayer> template<class NextLayer>
template<class Allocator, class Decorator> template<class Body, class Allocator,
class Decorator>
void void
stream<NextLayer>:: stream<NextLayer>::
do_accept(http::header<true, do_accept(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
Decorator const& decorator, error_code& ec) Decorator const& decorator, error_code& ec)
{ {
@@ -652,7 +653,7 @@ do_handshake(response_type* res_p,
template<class NextLayer> template<class NextLayer>
void void
stream<NextLayer>:: stream<NextLayer>::
do_response(http::header<false> const& res, do_response(response_type const& res,
detail::sec_ws_key_type const& key, error_code& ec) detail::sec_ws_key_type const& key, error_code& ec)
{ {
bool const success = [&]() bool const success = [&]()

View File

@@ -999,9 +999,10 @@ public:
@throws system_error Thrown on failure. @throws system_error Thrown on failure.
*/ */
template<class Allocator> template<class Body, class Allocator>
void void
accept(http::header<true, http::basic_fields<Allocator>> const& req); accept(http::request<Body,
http::basic_fields<Allocator>> const& req);
/** Respond to a WebSocket HTTP Upgrade request /** Respond to a WebSocket HTTP Upgrade request
@@ -1040,9 +1041,10 @@ public:
@throws system_error Thrown on failure. @throws system_error Thrown on failure.
*/ */
template<class Allocator, class ResponseDecorator> template<class Body, class Allocator,
class ResponseDecorator>
void void
accept_ex(http::header<true, accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator); ResponseDecorator const& decorator);
@@ -1074,10 +1076,11 @@ public:
@param ec Set to indicate what error occurred, if any. @param ec Set to indicate what error occurred, if any.
*/ */
template<class Allocator> template<class Body, class Allocator>
void void
accept(http::header<true, http::basic_fields<Allocator>> const& req, accept(http::request<Body,
error_code& ec); http::basic_fields<Allocator>> const& req,
error_code& ec);
/** Respond to a WebSocket HTTP Upgrade request /** Respond to a WebSocket HTTP Upgrade request
@@ -1116,9 +1119,10 @@ public:
@param ec Set to indicate what error occurred, if any. @param ec Set to indicate what error occurred, if any.
*/ */
template<class Allocator, class ResponseDecorator> template<class Body, class Allocator,
class ResponseDecorator>
void void
accept_ex(http::header<true, accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator, ResponseDecorator const& decorator,
error_code& ec); error_code& ec);
@@ -1156,10 +1160,12 @@ public:
@throws system_error Thrown on failure. @throws system_error Thrown on failure.
*/ */
template<class Allocator, class ConstBufferSequence> template<class Body, class Allocator,
class ConstBufferSequence>
void void
accept(http::header<true, http::basic_fields<Allocator>> const& req, accept(http::request<Body,
ConstBufferSequence const& buffers); http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers);
/** Respond to a WebSocket HTTP Upgrade request /** Respond to a WebSocket HTTP Upgrade request
@@ -1203,10 +1209,10 @@ public:
@throws system_error Thrown on failure. @throws system_error Thrown on failure.
*/ */
template<class Allocator, class ConstBufferSequence, template<class Body, class Allocator,
class ResponseDecorator> class ConstBufferSequence, class ResponseDecorator>
void void
accept_ex(http::header<true, accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers, ConstBufferSequence const& buffers,
ResponseDecorator const& decorator); ResponseDecorator const& decorator);
@@ -1244,10 +1250,13 @@ public:
@param ec Set to indicate what error occurred, if any. @param ec Set to indicate what error occurred, if any.
*/ */
template<class Allocator, class ConstBufferSequence> template<class Body, class Allocator,
class ConstBufferSequence>
void void
accept(http::header<true, Allocator> const& req, accept(http::request<Body,
ConstBufferSequence const& buffers, error_code& ec); http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
error_code& ec);
/** Respond to a WebSocket HTTP Upgrade request /** Respond to a WebSocket HTTP Upgrade request
@@ -1291,10 +1300,10 @@ public:
@param ec Set to indicate what error occurred, if any. @param ec Set to indicate what error occurred, if any.
*/ */
template<class Allocator, class ConstBufferSequence, template<class Body, class Allocator,
class ResponseDecorator> class ConstBufferSequence, class ResponseDecorator>
void void
accept_ex(http::header<true, accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers, ConstBufferSequence const& buffers,
ResponseDecorator const& decorator, ResponseDecorator const& decorator,
@@ -1580,14 +1589,15 @@ public:
this function. Invocation of the handler will be performed in a 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 Allocator, class AcceptHandler> template<class Body, class Allocator,
class AcceptHandler>
#if BEAST_DOXYGEN #if BEAST_DOXYGEN
void_or_deduced void_or_deduced
#else #else
async_return_type< async_return_type<
AcceptHandler, void(error_code)> AcceptHandler, void(error_code)>
#endif #endif
async_accept(http::header<true, async_accept(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
AcceptHandler&& handler); AcceptHandler&& handler);
@@ -1645,7 +1655,7 @@ public:
this function. Invocation of the handler will be performed in a 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 Allocator, template<class Body, class Allocator,
class ResponseDecorator, class AcceptHandler> class ResponseDecorator, class AcceptHandler>
#if BEAST_DOXYGEN #if BEAST_DOXYGEN
void_or_deduced void_or_deduced
@@ -1653,7 +1663,7 @@ public:
async_return_type< async_return_type<
AcceptHandler, void(error_code)> AcceptHandler, void(error_code)>
#endif #endif
async_accept_ex(http::header<true, async_accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator, ResponseDecorator const& decorator,
AcceptHandler&& handler); AcceptHandler&& handler);
@@ -1710,7 +1720,7 @@ public:
this function. Invocation of the handler will be performed in a 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 Allocator, template<class Body, class Allocator,
class ConstBufferSequence, class AcceptHandler> class ConstBufferSequence, class AcceptHandler>
#if BEAST_DOXYGEN #if BEAST_DOXYGEN
void_or_deduced void_or_deduced
@@ -1718,7 +1728,7 @@ public:
async_return_type< async_return_type<
AcceptHandler, void(error_code)> AcceptHandler, void(error_code)>
#endif #endif
async_accept(http::header<true, async_accept(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers, ConstBufferSequence const& buffers,
AcceptHandler&& handler); AcceptHandler&& handler);
@@ -1784,19 +1794,23 @@ public:
this function. Invocation of the handler will be performed in a 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 Allocator, class ConstBufferSequence, template<
class ResponseDecorator, class AcceptHandler> class Body, class Allocator,
class ConstBufferSequence,
class ResponseDecorator,
class AcceptHandler>
#if BEAST_DOXYGEN #if BEAST_DOXYGEN
void_or_deduced void_or_deduced
#else #else
async_return_type< async_return_type<
AcceptHandler, void(error_code)> AcceptHandler, void(error_code)>
#endif #endif
async_accept_ex(http::header<true, async_accept_ex(
http::basic_fields<Allocator>> const& req, http::request<Body,
ConstBufferSequence const& buffers, http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator, ConstBufferSequence const& buffers,
AcceptHandler&& handler); ResponseDecorator const& decorator,
AcceptHandler&& handler);
/** Send an HTTP WebSocket Upgrade request and receive the response. /** Send an HTTP WebSocket Upgrade request and receive the response.
@@ -3326,9 +3340,10 @@ private:
string_view target, string_view target,
Decorator const& decorator); Decorator const& decorator);
template<class Allocator, class Decorator> template<class Body,
class Allocator, class Decorator>
response_type response_type
build_response(http::header<true, build_response(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
Decorator const& decorator); Decorator const& decorator);
@@ -3337,22 +3352,22 @@ private:
do_accept(Decorator const& decorator, do_accept(Decorator const& decorator,
error_code& ec); error_code& ec);
template<class Allocator, class Decorator> template<class Body, class Allocator,
class Decorator>
void void
do_accept(http::header<true, do_accept(http::request<Body,
http::basic_fields<Allocator>> const& req, http::basic_fields<Allocator>> const& req,
Decorator const& decorator, error_code& ec); Decorator const& decorator, error_code& ec);
template<class RequestDecorator> template<class RequestDecorator>
void void
do_handshake(response_type* res_p, do_handshake(response_type* res_p,
string_view host, string_view host, string_view target,
string_view target, RequestDecorator const& decorator,
RequestDecorator const& decorator, error_code& ec);
error_code& ec);
void void
do_response(http::header<false> const& resp, do_response(response_type const& resp,
detail::sec_ws_key_type const& key, error_code& ec); detail::sec_ws_key_type const& key, error_code& ec);
}; };

View File

@@ -138,19 +138,18 @@ public:
ws.accept(buffers); ws.accept(buffers);
} }
template<class NextLayer, class Fields> template<class NextLayer>
void void
accept(stream<NextLayer>& ws, accept(stream<NextLayer>& ws,
http::header<true, Fields> const& req) const http::request<http::empty_body> const& req) const
{ {
ws.accept(req); ws.accept(req);
} }
template<class NextLayer, template<class NextLayer, class Buffers>
class Fields, class Buffers>
void void
accept(stream<NextLayer>& ws, accept(stream<NextLayer>& ws,
http::header<true, Fields> const& req, http::request<http::empty_body> const& req,
Buffers const& buffers) const Buffers const& buffers) const
{ {
ws.accept(req, buffers); ws.accept(req, buffers);
@@ -175,22 +174,20 @@ public:
ws.accept_ex(buffers, d); ws.accept_ex(buffers, d);
} }
template<class NextLayer, template<class NextLayer, class Decorator>
class Fields, class Decorator>
void void
accept_ex(stream<NextLayer>& ws, accept_ex(stream<NextLayer>& ws,
http::header<true, Fields> const& req, http::request<http::empty_body> const& req,
Decorator const& d) const Decorator const& d) const
{ {
ws.accept_ex(req, d); ws.accept_ex(req, d);
} }
template<class NextLayer, template<class NextLayer,
class Fields, class Buffers, class Buffers, class Decorator>
class Decorator>
void void
accept_ex(stream<NextLayer>& ws, accept_ex(stream<NextLayer>& ws,
http::header<true, Fields> const& req, http::request<http::empty_body> const& req,
Buffers const& buffers, Buffers const& buffers,
Decorator const& d) const Decorator const& d) const
{ {
@@ -332,10 +329,10 @@ public:
throw system_error{ec}; throw system_error{ec};
} }
template<class NextLayer, class Fields> template<class NextLayer>
void void
accept(stream<NextLayer>& ws, accept(stream<NextLayer>& ws,
http::header<true, Fields> const& req) const http::request<http::empty_body> const& req) const
{ {
error_code ec; error_code ec;
ws.async_accept(req, yield_[ec]); ws.async_accept(req, yield_[ec]);
@@ -343,11 +340,10 @@ public:
throw system_error{ec}; throw system_error{ec};
} }
template<class NextLayer, template<class NextLayer, class Buffers>
class Fields, class Buffers>
void void
accept(stream<NextLayer>& ws, accept(stream<NextLayer>& ws,
http::header<true, Fields> const& req, http::request<http::empty_body> const& req,
Buffers const& buffers) const Buffers const& buffers) const
{ {
error_code ec; error_code ec;
@@ -382,11 +378,10 @@ public:
throw system_error{ec}; throw system_error{ec};
} }
template<class NextLayer, template<class NextLayer, class Decorator>
class Fields, class Decorator>
void void
accept_ex(stream<NextLayer>& ws, accept_ex(stream<NextLayer>& ws,
http::header<true, Fields> const& req, http::request<http::empty_body> const& req,
Decorator const& d) const Decorator const& d) const
{ {
error_code ec; error_code ec;
@@ -395,11 +390,11 @@ public:
throw system_error{ec}; throw system_error{ec};
} }
template<class NextLayer, class Fields, template<class NextLayer,
class Buffers, class Decorator> class Buffers, class Decorator>
void void
accept_ex(stream<NextLayer>& ws, accept_ex(stream<NextLayer>& ws,
http::header<true, Fields> const& req, http::request<http::empty_body> const& req,
Buffers const& buffers, Buffers const& buffers,
Decorator const& d) const Decorator const& d) const
{ {