forked from boostorg/beast
Refactor http::header contents (API Change):
fix #124 The http::header data members "method", "url", and "reason" are changed from data members, to pairs of get and set functions which forward the call to the Fields type used to instantiate the template. Previously, these data members were implemented using std::string. With this change, the implementation of the Fields type used to instantiate the template is now in control of the representation of those values. This permits custom memory allocation strategies including uniform use of the Allocator type already provided to beast::http::basic_fields.
This commit is contained in:
1 parent
dd02097d26
commit
ff5e659545
30 files changed
+319
-213
No files matched your search
@@ -43,14 +43,14 @@ class stream<NextLayer>::handshake_op
|
||||
data(Handler& handler, stream<NextLayer>& ws_,
|
||||
response_type* res_p_,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
Decorator const& decorator)
|
||||
: cont(beast_asio_helpers::
|
||||
is_continuation(handler))
|
||||
, ws(ws_)
|
||||
, res_p(res_p_)
|
||||
, req(ws.build_request(key,
|
||||
host, resource, decorator))
|
||||
host, target, decorator))
|
||||
{
|
||||
ws.reset();
|
||||
}
|
||||
@@ -164,7 +164,7 @@ typename async_completion<HandshakeHandler,
|
||||
void(error_code)>::result_type
|
||||
stream<NextLayer>::
|
||||
async_handshake(boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
HandshakeHandler&& handler)
|
||||
{
|
||||
static_assert(is_AsyncStream<next_layer_type>::value,
|
||||
@@ -173,7 +173,7 @@ async_handshake(boost::string_ref const& host,
|
||||
void(error_code)> completion{handler};
|
||||
handshake_op<decltype(completion.handler)>{
|
||||
completion.handler, *this, nullptr,
|
||||
host, resource, &default_decorate_req};
|
||||
host, target, &default_decorate_req};
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ typename async_completion<HandshakeHandler,
|
||||
stream<NextLayer>::
|
||||
async_handshake(response_type& res,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
HandshakeHandler&& handler)
|
||||
{
|
||||
static_assert(is_AsyncStream<next_layer_type>::value,
|
||||
@@ -193,7 +193,7 @@ async_handshake(response_type& res,
|
||||
void(error_code)> completion{handler};
|
||||
handshake_op<decltype(completion.handler)>{
|
||||
completion.handler, *this, &res,
|
||||
host, resource, &default_decorate_req};
|
||||
host, target, &default_decorate_req};
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ typename async_completion<HandshakeHandler,
|
||||
void(error_code)>::result_type
|
||||
stream<NextLayer>::
|
||||
async_handshake_ex(boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
RequestDecorator const& decorator,
|
||||
HandshakeHandler&& handler)
|
||||
{
|
||||
@@ -216,7 +216,7 @@ async_handshake_ex(boost::string_ref const& host,
|
||||
void(error_code)> completion{handler};
|
||||
handshake_op<decltype(completion.handler)>{
|
||||
completion.handler, *this, nullptr,
|
||||
host, resource, decorator};
|
||||
host, target, decorator};
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ typename async_completion<HandshakeHandler,
|
||||
stream<NextLayer>::
|
||||
async_handshake_ex(response_type& res,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
RequestDecorator const& decorator,
|
||||
HandshakeHandler&& handler)
|
||||
{
|
||||
@@ -240,7 +240,7 @@ async_handshake_ex(response_type& res,
|
||||
void(error_code)> completion{handler};
|
||||
handshake_op<decltype(completion.handler)>{
|
||||
completion.handler, *this, &res,
|
||||
host, resource, decorator};
|
||||
host, target, decorator};
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
@@ -248,13 +248,13 @@ template<class NextLayer>
|
||||
void
|
||||
stream<NextLayer>::
|
||||
handshake(boost::string_ref const& host,
|
||||
boost::string_ref const& resource)
|
||||
boost::string_ref const& target)
|
||||
{
|
||||
static_assert(is_SyncStream<next_layer_type>::value,
|
||||
"SyncStream requirements not met");
|
||||
error_code ec;
|
||||
handshake(
|
||||
host, resource, ec);
|
||||
host, target, ec);
|
||||
if(ec)
|
||||
throw system_error{ec};
|
||||
}
|
||||
@@ -264,12 +264,12 @@ void
|
||||
stream<NextLayer>::
|
||||
handshake(response_type& res,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource)
|
||||
boost::string_ref const& target)
|
||||
{
|
||||
static_assert(is_SyncStream<next_layer_type>::value,
|
||||
"SyncStream requirements not met");
|
||||
error_code ec;
|
||||
handshake(res, host, resource, ec);
|
||||
handshake(res, host, target, ec);
|
||||
if(ec)
|
||||
throw system_error{ec};
|
||||
}
|
||||
@@ -279,7 +279,7 @@ template<class RequestDecorator>
|
||||
void
|
||||
stream<NextLayer>::
|
||||
handshake_ex(boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
RequestDecorator const& decorator)
|
||||
{
|
||||
static_assert(is_SyncStream<next_layer_type>::value,
|
||||
@@ -288,7 +288,7 @@ handshake_ex(boost::string_ref const& host,
|
||||
RequestDecorator>::value,
|
||||
"RequestDecorator requirements not met");
|
||||
error_code ec;
|
||||
handshake_ex(host, resource, decorator, ec);
|
||||
handshake_ex(host, target, decorator, ec);
|
||||
if(ec)
|
||||
throw system_error{ec};
|
||||
}
|
||||
@@ -299,7 +299,7 @@ void
|
||||
stream<NextLayer>::
|
||||
handshake_ex(response_type& res,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
RequestDecorator const& decorator)
|
||||
{
|
||||
static_assert(is_SyncStream<next_layer_type>::value,
|
||||
@@ -308,7 +308,7 @@ handshake_ex(response_type& res,
|
||||
RequestDecorator>::value,
|
||||
"RequestDecorator requirements not met");
|
||||
error_code ec;
|
||||
handshake_ex(res, host, resource, decorator, ec);
|
||||
handshake_ex(res, host, target, decorator, ec);
|
||||
if(ec)
|
||||
throw system_error{ec};
|
||||
}
|
||||
@@ -317,12 +317,12 @@ template<class NextLayer>
|
||||
void
|
||||
stream<NextLayer>::
|
||||
handshake(boost::string_ref const& host,
|
||||
boost::string_ref const& resource, error_code& ec)
|
||||
boost::string_ref const& target, error_code& ec)
|
||||
{
|
||||
static_assert(is_SyncStream<next_layer_type>::value,
|
||||
"SyncStream requirements not met");
|
||||
do_handshake(nullptr,
|
||||
host, resource, &default_decorate_req, ec);
|
||||
host, target, &default_decorate_req, ec);
|
||||
}
|
||||
|
||||
template<class NextLayer>
|
||||
@@ -330,13 +330,13 @@ void
|
||||
stream<NextLayer>::
|
||||
handshake(response_type& res,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
error_code& ec)
|
||||
{
|
||||
static_assert(is_SyncStream<next_layer_type>::value,
|
||||
"SyncStream requirements not met");
|
||||
do_handshake(&res,
|
||||
host, resource, &default_decorate_req, ec);
|
||||
host, target, &default_decorate_req, ec);
|
||||
}
|
||||
|
||||
template<class NextLayer>
|
||||
@@ -344,7 +344,7 @@ template<class RequestDecorator>
|
||||
void
|
||||
stream<NextLayer>::
|
||||
handshake_ex(boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
RequestDecorator const& decorator,
|
||||
error_code& ec)
|
||||
{
|
||||
@@ -354,7 +354,7 @@ handshake_ex(boost::string_ref const& host,
|
||||
RequestDecorator>::value,
|
||||
"RequestDecorator requirements not met");
|
||||
do_handshake(nullptr,
|
||||
host, resource, decorator, ec);
|
||||
host, target, decorator, ec);
|
||||
}
|
||||
|
||||
template<class NextLayer>
|
||||
@@ -363,7 +363,7 @@ void
|
||||
stream<NextLayer>::
|
||||
handshake_ex(response_type& res,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
RequestDecorator const& decorator,
|
||||
error_code& ec)
|
||||
{
|
||||
@@ -373,7 +373,7 @@ handshake_ex(response_type& res,
|
||||
RequestDecorator>::value,
|
||||
"RequestDecorator requirements not met");
|
||||
do_handshake(&res,
|
||||
host, resource, decorator, ec);
|
||||
host, target, decorator, ec);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -19,7 +19,7 @@ is_upgrade(http::header<true, Fields> const& req)
|
||||
{
|
||||
if(req.version < 11)
|
||||
return false;
|
||||
if(req.method != "GET")
|
||||
if(req.method() != "GET")
|
||||
return false;
|
||||
if(! http::is_upgrade(req))
|
||||
return false;
|
||||
|
||||
@@ -128,7 +128,7 @@ void
|
||||
stream<NextLayer>::
|
||||
do_handshake(response_type* res_p,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
RequestDecorator const& decorator,
|
||||
error_code& ec)
|
||||
{
|
||||
@@ -137,7 +137,7 @@ do_handshake(response_type* res_p,
|
||||
detail::sec_ws_key_type key;
|
||||
{
|
||||
auto const req = build_request(
|
||||
key, host, resource, decorator);
|
||||
key, host, target, decorator);
|
||||
pmd_read(pmd_config_, req.fields);
|
||||
http::write(stream_, req, ec);
|
||||
}
|
||||
@@ -157,13 +157,13 @@ request_type
|
||||
stream<NextLayer>::
|
||||
build_request(detail::sec_ws_key_type& key,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
Decorator const& decorator)
|
||||
{
|
||||
request_type req;
|
||||
req.url = { resource.data(), resource.size() };
|
||||
req.target(target);
|
||||
req.version = 11;
|
||||
req.method = "GET";
|
||||
req.method("GET");
|
||||
req.fields.insert("Host", host);
|
||||
req.fields.insert("Upgrade", "websocket");
|
||||
req.fields.insert("Connection", "upgrade");
|
||||
@@ -215,7 +215,7 @@ build_response(request_type const& req,
|
||||
{
|
||||
response_type res;
|
||||
res.status = 400;
|
||||
res.reason = http::reason_string(res.status);
|
||||
res.reason(http::reason_string(res.status));
|
||||
res.version = req.version;
|
||||
res.body = text;
|
||||
prepare(res);
|
||||
@@ -224,7 +224,7 @@ build_response(request_type const& req,
|
||||
};
|
||||
if(req.version < 11)
|
||||
return err("HTTP version 1.1 required");
|
||||
if(req.method != "GET")
|
||||
if(req.method() != "GET")
|
||||
return err("Wrong method");
|
||||
if(! is_upgrade(req))
|
||||
return err("Expected Upgrade request");
|
||||
@@ -246,7 +246,7 @@ build_response(request_type const& req,
|
||||
{
|
||||
response_type res;
|
||||
res.status = 426;
|
||||
res.reason = http::reason_string(res.status);
|
||||
res.reason(http::reason_string(res.status));
|
||||
res.version = req.version;
|
||||
res.fields.insert("Sec-WebSocket-Version", "13");
|
||||
prepare(res);
|
||||
@@ -264,7 +264,7 @@ build_response(request_type const& req,
|
||||
res.fields, unused, offer, pmd_opts_);
|
||||
}
|
||||
res.status = 101;
|
||||
res.reason = http::reason_string(res.status);
|
||||
res.reason(http::reason_string(res.status));
|
||||
res.version = req.version;
|
||||
res.fields.insert("Upgrade", "websocket");
|
||||
res.fields.insert("Connection", "upgrade");
|
||||
|
||||
@@ -1445,7 +1445,7 @@ public:
|
||||
@param host The name of the remote host,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@param resource The requesting URI, which may not be empty,
|
||||
@param target The Request Target, which may not be empty,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@throws system_error Thrown on failure.
|
||||
@@ -1466,7 +1466,7 @@ public:
|
||||
*/
|
||||
void
|
||||
handshake(boost::string_ref const& host,
|
||||
boost::string_ref const& resource);
|
||||
boost::string_ref const& target);
|
||||
|
||||
/** Send an HTTP WebSocket Upgrade request and receive the response.
|
||||
|
||||
@@ -1492,7 +1492,7 @@ public:
|
||||
@param host The name of the remote host,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@param resource The requesting URI, which may not be empty,
|
||||
@param target The Request Target, which may not be empty,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@throws system_error Thrown on failure.
|
||||
@@ -1515,7 +1515,7 @@ public:
|
||||
void
|
||||
handshake(response_type& res,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource);
|
||||
boost::string_ref const& target);
|
||||
|
||||
/** Send an HTTP WebSocket Upgrade request and receive the response.
|
||||
|
||||
@@ -1538,7 +1538,7 @@ public:
|
||||
@param host The name of the remote host,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@param resource The requesting URI, which may not be empty,
|
||||
@param target The Request Target, which may not be empty,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@param decorator A function object which will be called to modify
|
||||
@@ -1573,7 +1573,7 @@ public:
|
||||
template<class RequestDecorator>
|
||||
void
|
||||
handshake_ex(boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
RequestDecorator const& decorator);
|
||||
|
||||
/** Send an HTTP WebSocket Upgrade request and receive the response.
|
||||
@@ -1600,7 +1600,7 @@ public:
|
||||
@param host The name of the remote host,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@param resource The requesting URI, which may not be empty,
|
||||
@param target The Request Target, which may not be empty,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@param decorator A function object which will be called to modify
|
||||
@@ -1637,7 +1637,7 @@ public:
|
||||
void
|
||||
handshake_ex(response_type& res,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
RequestDecorator const& decorator);
|
||||
|
||||
/** Send an HTTP WebSocket Upgrade request and receive the response.
|
||||
@@ -1661,7 +1661,7 @@ public:
|
||||
@param host The name of the remote host,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@param resource The requesting URI, which may not be empty,
|
||||
@param target The Request Target, which may not be empty,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@param ec Set to indicate what error occurred, if any.
|
||||
@@ -1671,7 +1671,7 @@ public:
|
||||
websocket::stream<ip::tcp::socket> ws{io_service};
|
||||
...
|
||||
error_code ec;
|
||||
ws.handshake(host, resource, ec);
|
||||
ws.handshake(host, target, ec);
|
||||
if(ec)
|
||||
{
|
||||
// An error occurred.
|
||||
@@ -1680,7 +1680,7 @@ public:
|
||||
*/
|
||||
void
|
||||
handshake(boost::string_ref const& host,
|
||||
boost::string_ref const& resource, error_code& ec);
|
||||
boost::string_ref const& target, error_code& ec);
|
||||
|
||||
/** Send an HTTP WebSocket Upgrade request and receive the response.
|
||||
|
||||
@@ -1703,7 +1703,7 @@ public:
|
||||
@param host The name of the remote host,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@param resource The requesting URI, which may not be empty,
|
||||
@param target The Request Target, which may not be empty,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@param ec Set to indicate what error occurred, if any.
|
||||
@@ -1717,7 +1717,7 @@ public:
|
||||
...
|
||||
error_code ec;
|
||||
response_type res;
|
||||
ws.handshake(res, host, resource, ec);
|
||||
ws.handshake(res, host, target, ec);
|
||||
if(ec)
|
||||
{
|
||||
// An error occurred.
|
||||
@@ -1727,7 +1727,7 @@ public:
|
||||
void
|
||||
handshake(response_type& res,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
error_code& ec);
|
||||
|
||||
/** Send an HTTP WebSocket Upgrade request and receive the response.
|
||||
@@ -1751,7 +1751,7 @@ public:
|
||||
@param host The name of the remote host,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@param resource The requesting URI, which may not be empty,
|
||||
@param target The Request Target, which may not be empty,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@param decorator A function object which will be called to modify
|
||||
@@ -1785,7 +1785,7 @@ public:
|
||||
template<class RequestDecorator>
|
||||
void
|
||||
handshake_ex(boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
RequestDecorator const& decorator,
|
||||
error_code& ec);
|
||||
|
||||
@@ -1813,7 +1813,7 @@ public:
|
||||
@param host The name of the remote host,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@param resource The requesting URI, which may not be empty,
|
||||
@param target The Request Target, which may not be empty,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@param decorator A function object which will be called to modify
|
||||
@@ -1849,7 +1849,7 @@ public:
|
||||
void
|
||||
handshake_ex(response_type& res,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
RequestDecorator const& decorator,
|
||||
error_code& ec);
|
||||
|
||||
@@ -1879,9 +1879,9 @@ public:
|
||||
@param host The name of the remote host, required by
|
||||
the HTTP protocol. Copies may be made as needed.
|
||||
|
||||
@param resource The requesting URI, which may not be empty,
|
||||
required by the HTTP protocol. Copies may be made as
|
||||
needed.
|
||||
@param target The Request Target, which may not be empty,
|
||||
required by the HTTP protocol. Copies of this parameter may
|
||||
be made as needed.
|
||||
|
||||
@param handler The handler to be called when the request completes.
|
||||
Copies will be made of the handler as required. The equivalent
|
||||
@@ -1902,7 +1902,7 @@ public:
|
||||
void(error_code)>::result_type
|
||||
#endif
|
||||
async_handshake(boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
HandshakeHandler&& handler);
|
||||
|
||||
/** Start an asynchronous operation to send an upgrade request and receive the response.
|
||||
@@ -1935,9 +1935,9 @@ public:
|
||||
@param host The name of the remote host, required by
|
||||
the HTTP protocol. Copies may be made as needed.
|
||||
|
||||
@param resource The requesting URI, which may not be empty,
|
||||
required by the HTTP protocol. Copies may be made as
|
||||
needed.
|
||||
@param target The Request Target, which may not be empty,
|
||||
required by the HTTP protocol. Copies of this parameter may
|
||||
be made as needed.
|
||||
|
||||
@param handler The handler to be called when the request completes.
|
||||
Copies will be made of the handler as required. The equivalent
|
||||
@@ -1959,7 +1959,7 @@ public:
|
||||
#endif
|
||||
async_handshake(response_type& res,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
HandshakeHandler&& handler);
|
||||
|
||||
/** Start an asynchronous operation to send an upgrade request and receive the response.
|
||||
@@ -1988,9 +1988,9 @@ public:
|
||||
@param host The name of the remote host, required by
|
||||
the HTTP protocol. Copies may be made as needed.
|
||||
|
||||
@param resource The requesting URI, which may not be empty,
|
||||
required by the HTTP protocol. Copies may be made as
|
||||
needed.
|
||||
@param target The Request Target, which may not be empty,
|
||||
required by the HTTP protocol. Copies of this parameter may
|
||||
be made as needed.
|
||||
|
||||
@param decorator A function object which will be called to modify
|
||||
the HTTP request object generated by the implementation. This
|
||||
@@ -2020,7 +2020,7 @@ public:
|
||||
void(error_code)>::result_type
|
||||
#endif
|
||||
async_handshake_ex(boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
RequestDecorator const& decorator,
|
||||
HandshakeHandler&& handler);
|
||||
|
||||
@@ -2054,9 +2054,9 @@ public:
|
||||
@param host The name of the remote host, required by
|
||||
the HTTP protocol. Copies may be made as needed.
|
||||
|
||||
@param resource The requesting URI, which may not be empty,
|
||||
required by the HTTP protocol. Copies may be made as
|
||||
needed.
|
||||
@param target The Request Target, which may not be empty,
|
||||
required by the HTTP protocol. Copies of this parameter may
|
||||
be made as needed.
|
||||
|
||||
@param decorator A function object which will be called to modify
|
||||
the HTTP request object generated by the implementation. This
|
||||
@@ -2087,7 +2087,7 @@ public:
|
||||
#endif
|
||||
async_handshake_ex(response_type& res,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
RequestDecorator const& decorator,
|
||||
HandshakeHandler&& handler);
|
||||
|
||||
@@ -2969,7 +2969,7 @@ private:
|
||||
void
|
||||
do_handshake(response_type* res_p,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
RequestDecorator const& decorator,
|
||||
error_code& ec);
|
||||
|
||||
@@ -2977,7 +2977,7 @@ private:
|
||||
request_type
|
||||
build_request(detail::sec_ws_key_type& key,
|
||||
boost::string_ref const& host,
|
||||
boost::string_ref const& resource,
|
||||
boost::string_ref const& target,
|
||||
Decorator const& decorator);
|
||||
|
||||
template<class Decorator>
|
||||
|
||||
Reference in new issue
Block a user