Narrow the use of Fields parameters:

Every interface or implementation which operates on a templated
type Fields is evaluated to determine if basic_fields<Allocator>
is more appropriate, and changed if so.
This commit is contained in:
Vinnie Falco
2017-07-20 08:15:27 -07:00
parent 50902c3938
commit 087844c487
14 changed files with 172 additions and 142 deletions
@@ -66,9 +66,10 @@ parse_bits(string_view s)
// Parse permessage-deflate request fields
//
template<class Fields>
template<class Allocator>
void
pmd_read(pmd_offer& offer, Fields const& fields)
pmd_read(pmd_offer& offer,
http::basic_fields<Allocator> const& fields)
{
offer.accept = false;
offer.server_max_window_bits= 0;
@@ -194,9 +195,10 @@ pmd_read(pmd_offer& offer, Fields const& fields)
// Set permessage-deflate fields for a client offer
//
template<class Fields>
template<class Allocator>
void
pmd_write(Fields& fields, pmd_offer const& offer)
pmd_write(http::basic_fields<Allocator>& fields,
pmd_offer const& offer)
{
static_string<512> s;
s = "permessage-deflate";
@@ -239,10 +241,10 @@ pmd_write(Fields& fields, pmd_offer const& offer)
// Negotiate a permessage-deflate client offer
//
template<class Fields>
template<class Allocator>
void
pmd_negotiate(
Fields& fields,
http::basic_fields<Allocator>& fields,
pmd_offer& config,
pmd_offer const& offer,
permessage_deflate const& o)
+58 -46
View File
@@ -42,9 +42,9 @@ class stream<NextLayer>::response_op
response_type res;
int state = 0;
template<class Fields, class Decorator>
data(Handler&, stream<NextLayer>& ws_,
http::header<true, Fields> const& req,
template<class Allocator, class Decorator>
data(Handler&, stream<NextLayer>& ws_, http::header<
true, http::basic_fields<Allocator>> const& req,
Decorator const& decorator,
bool cont_)
: cont(cont_)
@@ -53,10 +53,10 @@ class stream<NextLayer>::response_op
{
}
template<class Fields,
template<class Allocator,
class Buffers, class Decorator>
data(Handler&, stream<NextLayer>& ws_,
http::header<true, Fields> const& req,
data(Handler&, stream<NextLayer>& ws_, http::header<
true, http::basic_fields<Allocator>> const& req,
Buffers const& buffers,
Decorator const& decorator,
bool cont_)
@@ -443,10 +443,11 @@ accept_ex(ConstBufferSequence const& buffers,
}
template<class NextLayer>
template<class Fields>
template<class Allocator>
void
stream<NextLayer>::
accept(http::header<true, Fields> const& req)
accept(http::header<true,
http::basic_fields<Allocator>> const& req)
{
static_assert(is_sync_stream<next_layer_type>::value,
"SyncStream requirements not met");
@@ -457,10 +458,11 @@ accept(http::header<true, Fields> const& req)
}
template<class NextLayer>
template<class Fields, class ResponseDecorator>
template<class Allocator, class ResponseDecorator>
void
stream<NextLayer>::
accept_ex(http::header<true, Fields> const& req,
accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator)
{
static_assert(is_sync_stream<next_layer_type>::value,
@@ -475,11 +477,12 @@ accept_ex(http::header<true, Fields> const& req,
}
template<class NextLayer>
template<class Fields>
template<class Allocator>
void
stream<NextLayer>::
accept(http::header<true, Fields> const& req,
error_code& ec)
accept(http::header<true,
http::basic_fields<Allocator>> const& req,
error_code& ec)
{
static_assert(is_sync_stream<next_layer_type>::value,
"SyncStream requirements not met");
@@ -488,11 +491,12 @@ accept(http::header<true, Fields> const& req,
}
template<class NextLayer>
template<class Fields, class ResponseDecorator>
template<class Allocator, class ResponseDecorator>
void
stream<NextLayer>::
accept_ex(http::header<true, Fields> const& req,
ResponseDecorator const& decorator, error_code& ec)
accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator, error_code& ec)
{
static_assert(is_sync_stream<next_layer_type>::value,
"SyncStream requirements not met");
@@ -504,11 +508,12 @@ accept_ex(http::header<true, Fields> const& req,
}
template<class NextLayer>
template<class Fields, class ConstBufferSequence>
template<class Allocator, class ConstBufferSequence>
void
stream<NextLayer>::
accept(http::header<true, Fields> const& req,
ConstBufferSequence const& buffers)
accept(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers)
{
static_assert(is_sync_stream<next_layer_type>::value,
"SyncStream requirements not met");
@@ -522,13 +527,14 @@ accept(http::header<true, Fields> const& req,
}
template<class NextLayer>
template<class Fields,
template<class Allocator,
class ConstBufferSequence, class ResponseDecorator>
void
stream<NextLayer>::
accept_ex(http::header<true, Fields> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator)
accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator)
{
static_assert(is_sync_stream<next_layer_type>::value,
"SyncStream requirements not met");
@@ -545,11 +551,12 @@ accept_ex(http::header<true, Fields> const& req,
}
template<class NextLayer>
template<class Fields, class ConstBufferSequence>
template<class Allocator, class ConstBufferSequence>
void
stream<NextLayer>::
accept(http::header<true, Fields> const& req,
ConstBufferSequence const& buffers, error_code& ec)
accept(http::header<true,
Allocator> const& req,
ConstBufferSequence const& buffers, error_code& ec)
{
static_assert(is_sync_stream<next_layer_type>::value,
"SyncStream requirements not met");
@@ -566,14 +573,15 @@ accept(http::header<true, Fields> const& req,
}
template<class NextLayer>
template<class Fields,
template<class Allocator,
class ConstBufferSequence, class ResponseDecorator>
void
stream<NextLayer>::
accept_ex(http::header<true, Fields> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
error_code& ec)
accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
error_code& ec)
{
static_assert(is_sync_stream<next_layer_type>::value,
"SyncStream requirements not met");
@@ -688,12 +696,13 @@ async_accept_ex(ConstBufferSequence const& buffers,
}
template<class NextLayer>
template<class Fields, class AcceptHandler>
template<class Allocator, class AcceptHandler>
async_return_type<
AcceptHandler, void(error_code)>
stream<NextLayer>::
async_accept(http::header<true, Fields> const& req,
AcceptHandler&& handler)
async_accept(http::header<true,
http::basic_fields<Allocator>> const& req,
AcceptHandler&& handler)
{
static_assert(is_async_stream<next_layer_type>::value,
"AsyncStream requirements requirements not met");
@@ -710,13 +719,14 @@ async_accept(http::header<true, Fields> const& req,
}
template<class NextLayer>
template<class Fields,
template<class Allocator,
class ResponseDecorator, class AcceptHandler>
async_return_type<
AcceptHandler, void(error_code)>
stream<NextLayer>::
async_accept_ex(http::header<true, Fields> const& req,
ResponseDecorator const& decorator, AcceptHandler&& handler)
async_accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator, AcceptHandler&& handler)
{
static_assert(is_async_stream<next_layer_type>::value,
"AsyncStream requirements requirements not met");
@@ -736,14 +746,15 @@ async_accept_ex(http::header<true, Fields> const& req,
}
template<class NextLayer>
template<class Fields,
template<class Allocator,
class ConstBufferSequence, class AcceptHandler>
async_return_type<
AcceptHandler, void(error_code)>
stream<NextLayer>::
async_accept(http::header<true, Fields> const& req,
ConstBufferSequence const& buffers,
AcceptHandler&& handler)
async_accept(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
AcceptHandler&& handler)
{
static_assert(is_async_stream<next_layer_type>::value,
"AsyncStream requirements requirements not met");
@@ -763,15 +774,16 @@ async_accept(http::header<true, Fields> const& req,
}
template<class NextLayer>
template<class Fields, class ConstBufferSequence,
template<class Allocator, class ConstBufferSequence,
class ResponseDecorator, class AcceptHandler>
async_return_type<
AcceptHandler, void(error_code)>
stream<NextLayer>::
async_accept_ex(http::header<true, Fields> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
AcceptHandler&& handler)
async_accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
AcceptHandler&& handler)
{
static_assert(is_async_stream<next_layer_type>::value,
"AsyncStream requirements requirements not met");
+4 -2
View File
@@ -8,14 +8,16 @@
#ifndef BEAST_WEBSOCKET_IMPL_RFC6455_IPP
#define BEAST_WEBSOCKET_IMPL_RFC6455_IPP
#include <beast/http/fields.hpp>
#include <beast/http/rfc7230.hpp>
namespace beast {
namespace websocket {
template<class Fields>
template<class Allocator>
bool
is_upgrade(http::header<true, Fields> const& req)
is_upgrade(http::header<true,
http::basic_fields<Allocator>> const& req)
{
if(req.version < 11)
return false;
+8 -6
View File
@@ -101,11 +101,12 @@ do_accept(
}
template<class NextLayer>
template<class Fields, class Decorator>
template<class Allocator, class Decorator>
void
stream<NextLayer>::
do_accept(http::header<true, Fields> const& req,
Decorator const& decorator, error_code& ec)
do_accept(http::header<true,
http::basic_fields<Allocator>> const& req,
Decorator const& decorator, error_code& ec)
{
auto const res = build_response(req, decorator);
http::write(stream_, res, ec);
@@ -192,11 +193,12 @@ build_request(detail::sec_ws_key_type& key,
}
template<class NextLayer>
template<class Fields, class Decorator>
template<class Allocator, class Decorator>
response_type
stream<NextLayer>::
build_response(http::header<true, Fields> const& req,
Decorator const& decorator)
build_response(http::header<true,
http::basic_fields<Allocator>> const& req,
Decorator const& decorator)
{
auto const decorate =
[&decorator](response_type& res)
+3 -2
View File
@@ -50,9 +50,10 @@ namespace websocket {
@return `true` if the request is a WebSocket Upgrade.
*/
template<class Fields>
template<class Allocator>
bool
is_upgrade(beast::http::header<true, Fields> const& req);
is_upgrade(beast::http::header<true,
http::basic_fields<Allocator>> const& req);
/** Close status codes.
+56 -46
View File
@@ -836,9 +836,9 @@ public:
@throws system_error Thrown on failure.
*/
template<class Fields>
template<class Allocator>
void
accept(http::header<true, Fields> const& req);
accept(http::header<true, http::basic_fields<Allocator>> const& req);
/** Respond to a WebSocket HTTP Upgrade request
@@ -877,10 +877,11 @@ public:
@throws system_error Thrown on failure.
*/
template<class Fields, class ResponseDecorator>
template<class Allocator, class ResponseDecorator>
void
accept_ex(http::header<true, Fields> const& req,
ResponseDecorator const& decorator);
accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator);
/** Respond to a WebSocket HTTP Upgrade request
@@ -910,9 +911,9 @@ public:
@param ec Set to indicate what error occurred, if any.
*/
template<class Fields>
template<class Allocator>
void
accept(http::header<true, Fields> const& req,
accept(http::header<true, http::basic_fields<Allocator>> const& req,
error_code& ec);
/** Respond to a WebSocket HTTP Upgrade request
@@ -952,11 +953,12 @@ public:
@param ec Set to indicate what error occurred, if any.
*/
template<class Fields, class ResponseDecorator>
template<class Allocator, class ResponseDecorator>
void
accept_ex(http::header<true, Fields> const& req,
ResponseDecorator const& decorator,
error_code& ec);
accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator,
error_code& ec);
/** Respond to a WebSocket HTTP Upgrade request
@@ -991,9 +993,9 @@ public:
@throws system_error Thrown on failure.
*/
template<class Fields, class ConstBufferSequence>
template<class Allocator, class ConstBufferSequence>
void
accept(http::header<true, Fields> const& req,
accept(http::header<true, http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers);
/** Respond to a WebSocket HTTP Upgrade request
@@ -1038,12 +1040,13 @@ public:
@throws system_error Thrown on failure.
*/
template<class Fields, class ConstBufferSequence,
template<class Allocator, class ConstBufferSequence,
class ResponseDecorator>
void
accept_ex(http::header<true, Fields> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator);
accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator);
/** Respond to a WebSocket HTTP Upgrade request
@@ -1078,9 +1081,9 @@ public:
@param ec Set to indicate what error occurred, if any.
*/
template<class Fields, class ConstBufferSequence>
template<class Allocator, class ConstBufferSequence>
void
accept(http::header<true, Fields> const& req,
accept(http::header<true, Allocator> const& req,
ConstBufferSequence const& buffers, error_code& ec);
/** Respond to a WebSocket HTTP Upgrade request
@@ -1125,13 +1128,14 @@ public:
@param ec Set to indicate what error occurred, if any.
*/
template<class Fields, class ConstBufferSequence,
template<class Allocator, class ConstBufferSequence,
class ResponseDecorator>
void
accept_ex(http::header<true, Fields> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
error_code& ec);
accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
error_code& ec);
/** Start reading and responding to a WebSocket HTTP Upgrade request.
@@ -1413,15 +1417,16 @@ public:
this function. Invocation of the handler will be performed in a
manner equivalent to using `boost::asio::io_service::post`.
*/
template<class Fields, class AcceptHandler>
template<class Allocator, class AcceptHandler>
#if BEAST_DOXYGEN
void_or_deduced
#else
async_return_type<
AcceptHandler, void(error_code)>
#endif
async_accept(http::header<true, Fields> const& req,
AcceptHandler&& handler);
async_accept(http::header<true,
http::basic_fields<Allocator>> const& req,
AcceptHandler&& handler);
/** Start responding to a WebSocket HTTP Upgrade request.
@@ -1477,7 +1482,7 @@ public:
this function. Invocation of the handler will be performed in a
manner equivalent to using `boost::asio::io_service::post`.
*/
template<class Fields,
template<class Allocator,
class ResponseDecorator, class AcceptHandler>
#if BEAST_DOXYGEN
void_or_deduced
@@ -1485,9 +1490,10 @@ public:
async_return_type<
AcceptHandler, void(error_code)>
#endif
async_accept_ex(http::header<true, Fields> const& req,
ResponseDecorator const& decorator,
AcceptHandler&& handler);
async_accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator,
AcceptHandler&& handler);
/** Start responding to a WebSocket HTTP Upgrade request.
@@ -1541,7 +1547,7 @@ public:
this function. Invocation of the handler will be performed in a
manner equivalent to using `boost::asio::io_service::post`.
*/
template<class Fields,
template<class Allocator,
class ConstBufferSequence, class AcceptHandler>
#if BEAST_DOXYGEN
void_or_deduced
@@ -1549,9 +1555,10 @@ public:
async_return_type<
AcceptHandler, void(error_code)>
#endif
async_accept(http::header<true, Fields> const& req,
ConstBufferSequence const& buffers,
AcceptHandler&& handler);
async_accept(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
AcceptHandler&& handler);
/** Start responding to a WebSocket HTTP Upgrade request.
@@ -1614,7 +1621,7 @@ public:
this function. Invocation of the handler will be performed in a
manner equivalent to using `boost::asio::io_service::post`.
*/
template<class Fields, class ConstBufferSequence,
template<class Allocator, class ConstBufferSequence,
class ResponseDecorator, class AcceptHandler>
#if BEAST_DOXYGEN
void_or_deduced
@@ -1622,10 +1629,11 @@ public:
async_return_type<
AcceptHandler, void(error_code)>
#endif
async_accept_ex(http::header<true, Fields> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
AcceptHandler&& handler);
async_accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
AcceptHandler&& handler);
/** Send an HTTP WebSocket Upgrade request and receive the response.
@@ -3109,10 +3117,11 @@ private:
do_accept(Decorator const& decorator,
error_code& ec);
template<class Fields, class Decorator>
template<class Allocator, class Decorator>
void
do_accept(http::header<true, Fields> const& req,
Decorator const& decorator, error_code& ec);
do_accept(http::header<true,
http::basic_fields<Allocator>> const& req,
Decorator const& decorator, error_code& ec);
template<class RequestDecorator>
void
@@ -3129,10 +3138,11 @@ private:
string_view target,
Decorator const& decorator);
template<class Fields, class Decorator>
template<class Allocator, class Decorator>
response_type
build_response(http::header<true, Fields> const& req,
Decorator const& decorator);
build_response(http::header<true,
http::basic_fields<Allocator>> const& req,
Decorator const& decorator);
void
do_response(http::header<false> const& resp,