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-06-19 13:01:59 -07:00
parent 50902c3938
commit 087844c487
14 changed files with 172 additions and 142 deletions

View File

@ -47,12 +47,12 @@ namespace http {
template<
class SyncStream,
class DynamicBuffer,
class Body, class Fields>
class Body, class Allocator>
void
send_expect_100_continue(
SyncStream& stream,
DynamicBuffer& buffer,
request<Body, Fields>& req,
request<Body, basic_fields<Allocator>>& req,
error_code& ec)
{
static_assert(is_sync_stream<SyncStream>::value,

View File

@ -273,12 +273,12 @@ public:
@param req The upgrade request.
*/
template<class Body, class Fields>
template<class Body>
void
on_upgrade(
socket_type&& sock,
endpoint_type ep,
beast::http::request<Body, Fields>&& req)
beast::http::request<Body>&& req)
{
// Create the connection and call the version of
// run that takes the request since we have it already
@ -304,12 +304,12 @@ public:
@param req The upgrade request.
*/
template<class Body, class Fields>
template<class Body>
void
on_upgrade(
ssl_stream<socket_type>&& stream,
endpoint_type ep,
beast::http::request<Body, Fields>&& req)
beast::http::request<Body>&& req)
{
std::make_shared<async_wss_con>(
std::move(stream),

View File

@ -26,9 +26,10 @@ namespace rfc7231 {
@see https://tools.ietf.org/html/rfc7231#section-5.1.1
*/
template<class Body, class Fields>
template<class Body, class Allocator>
bool
is_expect_100_continue(beast::http::request<Body, Fields> const& req)
is_expect_100_continue(beast::http::request<
Body, beast::http::basic_fields<Allocator>> const& req)
{
return beast::iequals(
req[beast::http::field::expect], "100-continue");

View File

@ -98,9 +98,9 @@ public:
@code
template<class Body, class Fields>
template<class Body>
void
send(response<Body, Fields>&&);
send(response<Body>&&);
@endcode
@ -112,13 +112,13 @@ public:
*/
template<
class Stream,
class Body, class Fields,
class Body,
class Send>
bool
respond(
Stream&& stream,
endpoint_type const& ep,
beast::http::request<Body, Fields>&& req,
beast::http::request<Body>&& req,
Send const& send) const
{
return try_respond(
@ -135,13 +135,13 @@ private:
*/
template<
class Stream,
class Body, class Fields,
class Body,
class Send>
bool
try_respond(
Stream&&,
endpoint_type const&,
beast::http::request<Body, Fields>&&,
beast::http::request<Body>&&,
Send const&,
C<sizeof...(Services)> const&) const
{
@ -155,14 +155,14 @@ private:
//
template<
class Stream,
class Body, class Fields,
class Body,
class Send,
std::size_t I>
bool
try_respond(
Stream&& stream,
endpoint_type const& ep,
beast::http::request<Body, Fields>&& req,
beast::http::request<Body>&& req,
Send const& send,
C<I> const&) const
{

View File

@ -90,9 +90,9 @@ public:
// This overload handles the case where we
// already have the WebSocket Upgrade request.
//
template<class Body, class Fields>
template<class Body>
void
run(beast::http::request<Body, Fields> const& req)
run(beast::http::request<Body> const& req)
{
// Call the overload of accept() which takes
// the request by parameter, instead of reading
@ -352,12 +352,12 @@ public:
@param req The upgrade request.
*/
template<class Body, class Fields>
template<class Body>
void
on_upgrade(
socket_type&& sock,
endpoint_type ep,
beast::http::request<Body, Fields>&& req)
beast::http::request<Body>&& req)
{
std::make_shared<async_ws_con>(
std::move(sock),

View File

@ -93,9 +93,9 @@ public:
// Run the connection from an already-received Upgrade request.
//
template<class Body, class Fields>
template<class Body>
void
run(beast::http::request<Body, Fields>&& req)
run(beast::http::request<Body>&& req)
{
BOOST_ASSERT(beast::websocket::is_upgrade(req));
@ -104,7 +104,7 @@ public:
// so we have to write it out by manually specifying the lambda.
//
std::thread{
lambda<Body, Fields>{
lambda<Body>{
impl().shared_from_this(),
std::move(req)
}}.detach();
@ -168,11 +168,11 @@ private:
// we write out the lambda ourselves. This is similar to what
// the compiler would generate anyway.
//
template<class Body, class Fields>
template<class Body>
class lambda
{
std::shared_ptr<sync_ws_con_base> self_;
beast::http::request<Body, Fields> req_;
beast::http::request<Body> req_;
public:
// Constructor
@ -181,7 +181,7 @@ private:
//
lambda(
std::shared_ptr<sync_ws_con_base> self,
beast::http::request<Body, Fields>&& req)
beast::http::request<Body>&& req)
: self_(std::move(self))
, req_(std::move(req))
{
@ -407,12 +407,12 @@ public:
@param req The upgrade request.
*/
template<class Body, class Fields>
template<class Body>
void
on_upgrade(
socket_type&& sock,
endpoint_type ep,
beast::http::request<Body, Fields>&& req)
beast::http::request<Body>&& req)
{
// Create the connection object and run it,
// transferring ownership of the ugprade request.

View File

@ -67,13 +67,13 @@ public:
*/
template<
class Stream,
class Body, class Fields,
class Body,
class Send>
bool
respond(
Stream&& stream,
endpoint_type const& ep,
beast::http::request<Body, Fields>&& req,
beast::http::request<Body>&& req,
Send const&) const
{
// If its not an upgrade request, return `false`

View File

@ -291,12 +291,12 @@ public:
@param req The upgrade request.
*/
template<class Body, class Fields>
template<class Body>
void
on_upgrade(
ssl_stream<socket_type>&& stream,
endpoint_type ep,
beast::http::request<Body, Fields>&& req)
beast::http::request<Body>&& req)
{
// Create the connection object and run it,
// transferring ownership of the ugprade request.
@ -415,12 +415,12 @@ public:
@param req The upgrade request.
*/
template<class Body, class Fields>
template<class Body>
void
on_upgrade(
ssl_stream<socket_type>&& stream,
endpoint_type ep,
beast::http::request<Body, Fields>&& req)
beast::http::request<Body>&& req)
{
std::make_shared<async_wss_con>(
std::move(stream),

View File

@ -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)

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,10 +477,11 @@ 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,
accept(http::header<true,
http::basic_fields<Allocator>> const& req,
error_code& ec)
{
static_assert(is_sync_stream<next_layer_type>::value,
@ -488,10 +491,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, error_code& ec)
{
static_assert(is_sync_stream<next_layer_type>::value,
@ -504,10 +508,11 @@ 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,
accept(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers)
{
static_assert(is_sync_stream<next_layer_type>::value,
@ -522,11 +527,12 @@ 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,
accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator)
{
@ -545,10 +551,11 @@ 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,
accept(http::header<true,
Allocator> const& req,
ConstBufferSequence const& buffers, error_code& ec)
{
static_assert(is_sync_stream<next_layer_type>::value,
@ -566,11 +573,12 @@ 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,
accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
error_code& ec)
@ -688,11 +696,12 @@ 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,
async_accept(http::header<true,
http::basic_fields<Allocator>> const& req,
AcceptHandler&& handler)
{
static_assert(is_async_stream<next_layer_type>::value,
@ -710,12 +719,13 @@ 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,
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,
@ -736,12 +746,13 @@ 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,
async_accept(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
AcceptHandler&& handler)
{
@ -763,12 +774,13 @@ 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,
async_accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
AcceptHandler&& handler)

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;

View File

@ -101,10 +101,11 @@ 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,
do_accept(http::header<true,
http::basic_fields<Allocator>> const& req,
Decorator const& decorator, error_code& ec)
{
auto const res = build_response(req, decorator);
@ -192,10 +193,11 @@ 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,
build_response(http::header<true,
http::basic_fields<Allocator>> const& req,
Decorator const& decorator)
{
auto const decorate =

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.

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,9 +877,10 @@ 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,
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,9 +953,10 @@ 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,
accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator,
error_code& ec);
@ -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,10 +1040,11 @@ 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,
accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator);
@ -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,10 +1128,11 @@ 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,
accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
error_code& ec);
@ -1413,14 +1417,15 @@ 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,
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,7 +1490,8 @@ public:
async_return_type<
AcceptHandler, void(error_code)>
#endif
async_accept_ex(http::header<true, Fields> const& req,
async_accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator,
AcceptHandler&& handler);
@ -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,7 +1555,8 @@ public:
async_return_type<
AcceptHandler, void(error_code)>
#endif
async_accept(http::header<true, Fields> const& req,
async_accept(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
AcceptHandler&& handler);
@ -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,7 +1629,8 @@ public:
async_return_type<
AcceptHandler, void(error_code)>
#endif
async_accept_ex(http::header<true, Fields> const& req,
async_accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
AcceptHandler&& handler);
@ -3109,9 +3117,10 @@ 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,
do_accept(http::header<true,
http::basic_fields<Allocator>> const& req,
Decorator const& decorator, error_code& ec);
template<class RequestDecorator>
@ -3129,9 +3138,10 @@ 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,
build_response(http::header<true,
http::basic_fields<Allocator>> const& req,
Decorator const& decorator);
void