mirror of
https://github.com/boostorg/beast.git
synced 2025-07-30 04:47:29 +02:00
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,3 +1,11 @@
|
||||
1.0.0-b39
|
||||
|
||||
API Changes:
|
||||
|
||||
* Refactor http::header contents
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
1.0.0-b38
|
||||
|
||||
* Refactor static_string
|
||||
|
@ -240,8 +240,8 @@ int main()
|
||||
|
||||
// Send HTTP request using beast
|
||||
beast::http::request<beast::http::string_body> req;
|
||||
req.method = "GET";
|
||||
req.url = "/";
|
||||
req.method("GET");
|
||||
req.target("/");
|
||||
req.version = 11;
|
||||
req.fields.replace("Host", host + ":" +
|
||||
boost::lexical_cast<std::string>(sock.remote_endpoint().port()));
|
||||
|
@ -35,8 +35,8 @@ int main()
|
||||
|
||||
// Send HTTP request using beast
|
||||
beast::http::request<beast::http::string_body> req;
|
||||
req.method = "GET";
|
||||
req.url = "/";
|
||||
req.method("GET");
|
||||
req.target("/");
|
||||
req.version = 11;
|
||||
req.fields.replace("Host", host + ":" +
|
||||
boost::lexical_cast<std::string>(sock.remote_endpoint().port()));
|
||||
|
12
doc/http.qbk
12
doc/http.qbk
@ -113,7 +113,7 @@ that type.
|
||||
This illustration shows the declarations and members of the __header__ and
|
||||
__message__ class templates, as well as the inheritance relationship:
|
||||
|
||||
[$images/message.png [width 650px] [height 390px]]
|
||||
[$images/message.png [width 711px] [height 424px]]
|
||||
|
||||
For notational convenience, these template type aliases are provided which
|
||||
supply typical choices for the [*`Fields`] type:
|
||||
@ -137,8 +137,8 @@ object:
|
||||
```
|
||||
request<string_body> req;
|
||||
req.version = 11; // HTTP/1.1
|
||||
req.method = "GET";
|
||||
req.url = "/index.htm"
|
||||
req.method("GET");
|
||||
req.target("/index.htm");
|
||||
req.fields.insert("Accept", "text/html");
|
||||
req.fields.insert("Connection", "keep-alive");
|
||||
req.fields.insert("User-Agent", "Beast");
|
||||
@ -148,7 +148,7 @@ object:
|
||||
response<string_body> res;
|
||||
res.version = 11; // HTTP/1.1
|
||||
res.status = 200;
|
||||
res.reason = "OK";
|
||||
res.reason("OK");
|
||||
res.fields.insert("Server", "Beast");
|
||||
res.fields.insert("Content-Length", 4);
|
||||
res.body = "****";
|
||||
@ -295,8 +295,8 @@ operations performed). To send messages synchronously, use one of the
|
||||
{
|
||||
request<string_body> req;
|
||||
req.version = 11;
|
||||
req.method = "GET";
|
||||
req.url = "/index.html";
|
||||
req.method("GET");
|
||||
req.target("/index.html");
|
||||
...
|
||||
write(sock, req); // Throws exception on error
|
||||
...
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 40 KiB |
@ -225,7 +225,7 @@ private:
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "read");
|
||||
auto path = req_.url;
|
||||
auto path = req_.target().to_string();
|
||||
if(path == "/")
|
||||
path = "/index.html";
|
||||
path = server_.root_ + path;
|
||||
@ -233,7 +233,7 @@ private:
|
||||
{
|
||||
response<string_body> res;
|
||||
res.status = 404;
|
||||
res.reason = "Not Found";
|
||||
res.reason("Not Found");
|
||||
res.version = req_.version;
|
||||
res.fields.insert("Server", "http_async_server");
|
||||
res.fields.insert("Content-Type", "text/html");
|
||||
@ -248,7 +248,7 @@ private:
|
||||
{
|
||||
resp_type res;
|
||||
res.status = 200;
|
||||
res.reason = "OK";
|
||||
res.reason("OK");
|
||||
res.version = req_.version;
|
||||
res.fields.insert("Server", "http_async_server");
|
||||
res.fields.insert("Content-Type", mime_type(path));
|
||||
@ -262,7 +262,7 @@ private:
|
||||
{
|
||||
response<string_body> res;
|
||||
res.status = 500;
|
||||
res.reason = "Internal Error";
|
||||
res.reason("Internal Error");
|
||||
res.version = req_.version;
|
||||
res.fields.insert("Server", "http_async_server");
|
||||
res.fields.insert("Content-Type", "text/html");
|
||||
|
@ -37,8 +37,8 @@ int main(int, char const*[])
|
||||
connect(sock, it);
|
||||
auto ep = sock.remote_endpoint();
|
||||
request<string_body> req;
|
||||
req.method = "GET";
|
||||
req.url = "/";
|
||||
req.method("GET");
|
||||
req.target("/");
|
||||
req.version = 11;
|
||||
req.fields.insert("Host", host + std::string(":") +
|
||||
boost::lexical_cast<std::string>(ep.port()));
|
||||
|
@ -23,8 +23,8 @@ int main()
|
||||
|
||||
// Send HTTP request using beast
|
||||
beast::http::request<beast::http::string_body> req;
|
||||
req.method = "GET";
|
||||
req.url = "/";
|
||||
req.method("GET");
|
||||
req.target("/");
|
||||
req.version = 11;
|
||||
req.fields.replace("Host", host + ":" +
|
||||
boost::lexical_cast<std::string>(sock.remote_endpoint().port()));
|
||||
|
@ -158,7 +158,7 @@ private:
|
||||
http::read(sock, sb, req, ec);
|
||||
if(ec)
|
||||
break;
|
||||
auto path = req.url;
|
||||
auto path = req.target().to_string();
|
||||
if(path == "/")
|
||||
path = "/index.html";
|
||||
path = root_ + path;
|
||||
@ -166,7 +166,7 @@ private:
|
||||
{
|
||||
response<string_body> res;
|
||||
res.status = 404;
|
||||
res.reason = "Not Found";
|
||||
res.reason("Not Found");
|
||||
res.version = req.version;
|
||||
res.fields.insert("Server", "http_sync_server");
|
||||
res.fields.insert("Content-Type", "text/html");
|
||||
@ -181,7 +181,7 @@ private:
|
||||
{
|
||||
resp_type res;
|
||||
res.status = 200;
|
||||
res.reason = "OK";
|
||||
res.reason("OK");
|
||||
res.version = req.version;
|
||||
res.fields.insert("Server", "http_sync_server");
|
||||
res.fields.insert("Content-Type", mime_type(path));
|
||||
@ -195,7 +195,7 @@ private:
|
||||
{
|
||||
response<string_body> res;
|
||||
res.status = 500;
|
||||
res.reason = "Internal Error";
|
||||
res.reason("Internal Error");
|
||||
res.version = req.version;
|
||||
res.fields.insert("Server", "http_sync_server");
|
||||
res.fields.insert("Content-Type", "text/html");
|
||||
|
@ -35,8 +35,8 @@ int main()
|
||||
|
||||
// Send HTTP request over SSL using Beast
|
||||
beast::http::request<beast::http::string_body> req;
|
||||
req.method = "GET";
|
||||
req.url = "/";
|
||||
req.method("GET");
|
||||
req.target("/");
|
||||
req.version = 11;
|
||||
req.fields.insert("Host", host + ":" +
|
||||
boost::lexical_cast<std::string>(sock.remote_endpoint().port()));
|
||||
|
@ -94,7 +94,7 @@ enum class parse_state
|
||||
void
|
||||
on_request(
|
||||
boost::string_ref const& method,
|
||||
boost::string_ref const& path,
|
||||
boost::string_ref const& target,
|
||||
int version,
|
||||
error_code& ec);
|
||||
|
||||
|
@ -285,7 +285,7 @@ protected:
|
||||
|
||||
static
|
||||
boost::string_ref
|
||||
parse_path(char const*& it)
|
||||
parse_target(char const*& it)
|
||||
{
|
||||
auto const first = it;
|
||||
while(is_pathchar(*it))
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <beast/core/detail/empty_base_optimization.hpp>
|
||||
#include <beast/http/detail/fields.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <memory>
|
||||
@ -297,6 +298,46 @@ public:
|
||||
replace(name,
|
||||
boost::lexical_cast<std::string>(value));
|
||||
}
|
||||
|
||||
#if BEAST_DOXYGEN
|
||||
private:
|
||||
#endif
|
||||
|
||||
boost::string_ref
|
||||
method() const
|
||||
{
|
||||
return (*this)[":method"];
|
||||
}
|
||||
|
||||
void
|
||||
method(boost::string_ref const& s)
|
||||
{
|
||||
return this->replace(":method", s);
|
||||
}
|
||||
|
||||
boost::string_ref
|
||||
target() const
|
||||
{
|
||||
return (*this)[":target"];
|
||||
}
|
||||
|
||||
void
|
||||
target(boost::string_ref const& s)
|
||||
{
|
||||
return this->replace(":target", s);
|
||||
}
|
||||
|
||||
boost::string_ref
|
||||
reason() const
|
||||
{
|
||||
return (*this)[":reason"];
|
||||
}
|
||||
|
||||
void
|
||||
reason(boost::string_ref const& s)
|
||||
{
|
||||
return this->replace(":reason", s);
|
||||
}
|
||||
};
|
||||
|
||||
/// A typical HTTP header fields container
|
||||
|
@ -112,10 +112,8 @@ private:
|
||||
boost::string_ref const& path,
|
||||
int version, error_code&)
|
||||
{
|
||||
h_.url = std::string{
|
||||
path.data(), path.size()};
|
||||
h_.method = std::string{
|
||||
method.data(), method.size()};
|
||||
h_.target(path);
|
||||
h_.method(method);
|
||||
h_.version = version;
|
||||
}
|
||||
|
||||
@ -125,9 +123,8 @@ private:
|
||||
int version, error_code&)
|
||||
{
|
||||
h_.status = status;
|
||||
h_.reason = std::string{
|
||||
reason.data(), reason.size()};
|
||||
h_.version = version;
|
||||
h_.reason(reason);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -396,8 +396,8 @@ parse_startline(char const*& it,
|
||||
return;
|
||||
}
|
||||
|
||||
auto const path = parse_path(it);
|
||||
if(path.empty())
|
||||
auto const target = parse_target(it);
|
||||
if(target.empty())
|
||||
{
|
||||
ec = error::bad_path;
|
||||
return;
|
||||
@ -416,7 +416,7 @@ parse_startline(char const*& it,
|
||||
}
|
||||
|
||||
impl().on_request(
|
||||
method, path, version, ec);
|
||||
method, target, version, ec);
|
||||
if(ec)
|
||||
return;
|
||||
}
|
||||
|
@ -28,8 +28,6 @@ swap(
|
||||
{
|
||||
using std::swap;
|
||||
swap(m1.version, m2.version);
|
||||
swap(m1.method, m2.method);
|
||||
swap(m1.url, m2.url);
|
||||
swap(m1.fields, m2.fields);
|
||||
}
|
||||
|
||||
@ -42,7 +40,6 @@ swap(
|
||||
using std::swap;
|
||||
swap(a.version, b.version);
|
||||
swap(a.status, b.status);
|
||||
swap(a.reason, b.reason);
|
||||
swap(a.fields, b.fields);
|
||||
}
|
||||
|
||||
@ -199,7 +196,7 @@ prepare(message<isRequest, Body, Fields>& msg,
|
||||
{
|
||||
using beast::detail::ci_equal;
|
||||
if(*pi.content_length > 0 ||
|
||||
ci_equal(msg.method, "POST"))
|
||||
ci_equal(msg.method(), "POST"))
|
||||
{
|
||||
msg.fields.insert(
|
||||
"Content-Length", *pi.content_length);
|
||||
|
@ -37,9 +37,9 @@ write_start_line(DynamicBuffer& dynabuf,
|
||||
header<true, Fields> const& msg)
|
||||
{
|
||||
BOOST_ASSERT(msg.version == 10 || msg.version == 11);
|
||||
write(dynabuf, msg.method);
|
||||
write(dynabuf, msg.method());
|
||||
write(dynabuf, " ");
|
||||
write(dynabuf, msg.url);
|
||||
write(dynabuf, msg.target());
|
||||
switch(msg.version)
|
||||
{
|
||||
case 10:
|
||||
@ -68,7 +68,7 @@ write_start_line(DynamicBuffer& dynabuf,
|
||||
}
|
||||
write(dynabuf, msg.status);
|
||||
write(dynabuf, " ");
|
||||
write(dynabuf, msg.reason);
|
||||
write(dynabuf, msg.reason());
|
||||
write(dynabuf, "\r\n");
|
||||
}
|
||||
|
||||
@ -82,6 +82,10 @@ write_fields(DynamicBuffer& dynabuf, FieldSequence const& fields)
|
||||
// "FieldSequence requirements not met");
|
||||
for(auto const& field : fields)
|
||||
{
|
||||
auto const name = field.name();
|
||||
BOOST_ASSERT(! name.empty());
|
||||
if(name[0] == ':')
|
||||
continue;
|
||||
write(dynabuf, field.name());
|
||||
write(dynabuf, ": ");
|
||||
write(dynabuf, field.value());
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <beast/config.hpp>
|
||||
#include <beast/http/fields.hpp>
|
||||
#include <beast/core/detail/integer_sequence.hpp>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
@ -65,17 +66,53 @@ struct header<true, Fields>
|
||||
*/
|
||||
int version;
|
||||
|
||||
/** The Request Method
|
||||
/** Return the Request Method
|
||||
|
||||
@note This field is present only if `isRequest == true`.
|
||||
@note This function is only available if `isRequest == true`.
|
||||
*/
|
||||
std::string method;
|
||||
auto
|
||||
method() const ->
|
||||
decltype(std::declval<Fields>().method()) const
|
||||
{
|
||||
return fields.method();
|
||||
}
|
||||
|
||||
/** The Request URI
|
||||
/** Set the Request Method
|
||||
|
||||
@note This field is present only if `isRequest == true`.
|
||||
@param value A value that represents the request method.
|
||||
|
||||
@note This function is only available if `isRequest == true`.
|
||||
*/
|
||||
std::string url;
|
||||
template<class Value>
|
||||
void
|
||||
method(Value&& value)
|
||||
{
|
||||
fields.method(std::forward<Value>(value));
|
||||
}
|
||||
|
||||
/** Return the Request Target
|
||||
|
||||
@note This function is only available if `isRequest == true`.
|
||||
*/
|
||||
auto
|
||||
target() const ->
|
||||
decltype(std::declval<Fields>().target()) const
|
||||
{
|
||||
return fields.target();
|
||||
}
|
||||
|
||||
/** Set the Request Target
|
||||
|
||||
@param value A value that represents the request method.
|
||||
|
||||
@note This function is only available if `isRequest == true`.
|
||||
*/
|
||||
template<class Value>
|
||||
void
|
||||
target(Value&& value)
|
||||
{
|
||||
fields.target(std::forward<Value>(value));
|
||||
}
|
||||
|
||||
/// The HTTP field values.
|
||||
fields_type fields;
|
||||
@ -197,17 +234,36 @@ struct header<false, Fields>
|
||||
|
||||
/** The Response Status-Code.
|
||||
|
||||
@note This field is present only if `isRequest == false`.
|
||||
@note This member is only available if `isRequest == false`.
|
||||
*/
|
||||
int status;
|
||||
|
||||
/** The Response Reason-Phrase.
|
||||
/** Return the Reason-Phrase.
|
||||
|
||||
The Reason-Phrase is obsolete as of rfc7230.
|
||||
|
||||
@note This field is present only if `isRequest == false`.
|
||||
@note This function is only available if `isRequest == false`.
|
||||
*/
|
||||
std::string reason;
|
||||
auto
|
||||
reason() const ->
|
||||
decltype(std::declval<Fields>().method()) const
|
||||
{
|
||||
return fields.reason();
|
||||
}
|
||||
|
||||
/** Set the Reason-Phrase
|
||||
|
||||
@param value A value that represents the reason phrase.
|
||||
|
||||
@note This function is only available if `isRequest == false`.
|
||||
*/
|
||||
template<class Value>
|
||||
void
|
||||
reason(Value&& value)
|
||||
{
|
||||
fields.reason(std::forward<Value>(value));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/** A container for a complete HTTP message.
|
||||
|
@ -158,13 +158,11 @@ private:
|
||||
void
|
||||
on_request(
|
||||
boost::string_ref const& method,
|
||||
boost::string_ref const& path,
|
||||
boost::string_ref const& target,
|
||||
int version, error_code&)
|
||||
{
|
||||
m_.url = std::string{
|
||||
path.data(), path.size()};
|
||||
m_.method = std::string{
|
||||
method.data(), method.size()};
|
||||
m_.target(target);
|
||||
m_.method(method);
|
||||
m_.version = version;
|
||||
}
|
||||
|
||||
@ -174,9 +172,8 @@ private:
|
||||
int version, error_code&)
|
||||
{
|
||||
m_.status = status;
|
||||
m_.reason = std::string{
|
||||
reason.data(), reason.size()};
|
||||
m_.version = version;
|
||||
m_.reason(reason);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -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>
|
||||
|
@ -70,7 +70,8 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
void testMessage()
|
||||
void
|
||||
testMessage()
|
||||
{
|
||||
static_assert(std::is_constructible<
|
||||
message<true, default_body, fields>>::value, "");
|
||||
@ -130,42 +131,43 @@ public:
|
||||
// swap
|
||||
message<true, string_body, fields> m1;
|
||||
message<true, string_body, fields> m2;
|
||||
m1.url = "u";
|
||||
m1.target("u");
|
||||
m1.body = "1";
|
||||
m1.fields.insert("h", "v");
|
||||
m2.method = "G";
|
||||
m2.method("G");
|
||||
m2.body = "2";
|
||||
swap(m1, m2);
|
||||
BEAST_EXPECT(m1.method == "G");
|
||||
BEAST_EXPECT(m2.method.empty());
|
||||
BEAST_EXPECT(m1.url.empty());
|
||||
BEAST_EXPECT(m2.url == "u");
|
||||
BEAST_EXPECT(m1.method() == "G");
|
||||
BEAST_EXPECT(m2.method().empty());
|
||||
BEAST_EXPECT(m1.target().empty());
|
||||
BEAST_EXPECT(m2.target() == "u");
|
||||
BEAST_EXPECT(m1.body == "2");
|
||||
BEAST_EXPECT(m2.body == "1");
|
||||
BEAST_EXPECT(! m1.fields.exists("h"));
|
||||
BEAST_EXPECT(m2.fields.exists("h"));
|
||||
}
|
||||
|
||||
struct MoveHeaders
|
||||
struct MoveFields : fields
|
||||
{
|
||||
bool moved_to = false;
|
||||
bool moved_from = false;
|
||||
|
||||
MoveHeaders() = default;
|
||||
MoveFields() = default;
|
||||
|
||||
MoveHeaders(MoveHeaders&& other)
|
||||
MoveFields(MoveFields&& other)
|
||||
: moved_to(true)
|
||||
{
|
||||
other.moved_from = true;
|
||||
}
|
||||
|
||||
MoveHeaders& operator=(MoveHeaders&& other)
|
||||
MoveFields& operator=(MoveFields&& other)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
void testHeaders()
|
||||
void
|
||||
testHeaders()
|
||||
{
|
||||
{
|
||||
using req_type = request_header;
|
||||
@ -182,22 +184,23 @@ public:
|
||||
}
|
||||
|
||||
{
|
||||
MoveHeaders h;
|
||||
header<true, MoveHeaders> r{std::move(h)};
|
||||
MoveFields h;
|
||||
header<true, MoveFields> r{std::move(h)};
|
||||
BEAST_EXPECT(h.moved_from);
|
||||
BEAST_EXPECT(r.fields.moved_to);
|
||||
request<string_body, MoveHeaders> m{std::move(r)};
|
||||
request<string_body, MoveFields> m{std::move(r)};
|
||||
BEAST_EXPECT(r.fields.moved_from);
|
||||
BEAST_EXPECT(m.fields.moved_to);
|
||||
}
|
||||
}
|
||||
|
||||
void testFreeFunctions()
|
||||
void
|
||||
testFreeFunctions()
|
||||
{
|
||||
{
|
||||
request<string_body> m;
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.version = 11;
|
||||
m.fields.insert("Upgrade", "test");
|
||||
BEAST_EXPECT(! is_upgrade(m));
|
||||
@ -211,7 +214,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void testPrepare()
|
||||
void
|
||||
testPrepare()
|
||||
{
|
||||
request<string_body> m;
|
||||
m.version = 10;
|
||||
@ -253,7 +257,8 @@ public:
|
||||
BEAST_EXPECT(! is_keep_alive(m));
|
||||
}
|
||||
|
||||
void testSwap()
|
||||
void
|
||||
testSwap()
|
||||
{
|
||||
message<false, string_body, fields> m1;
|
||||
message<false, string_body, fields> m2;
|
||||
@ -262,14 +267,14 @@ public:
|
||||
m1.body = "1";
|
||||
m1.fields.insert("h", "v");
|
||||
m2.status = 404;
|
||||
m2.reason = "OK";
|
||||
m2.reason("OK");
|
||||
m2.body = "2";
|
||||
m2.version = 11;
|
||||
swap(m1, m2);
|
||||
BEAST_EXPECT(m1.status == 404);
|
||||
BEAST_EXPECT(m2.status == 200);
|
||||
BEAST_EXPECT(m1.reason == "OK");
|
||||
BEAST_EXPECT(m2.reason.empty());
|
||||
BEAST_EXPECT(m1.reason() == "OK");
|
||||
BEAST_EXPECT(m2.reason().empty());
|
||||
BEAST_EXPECT(m1.version == 11);
|
||||
BEAST_EXPECT(m2.version == 10);
|
||||
BEAST_EXPECT(m1.body == "2");
|
||||
@ -291,7 +296,8 @@ public:
|
||||
}();
|
||||
}
|
||||
|
||||
void run() override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testMessage();
|
||||
testHeaders();
|
||||
|
@ -131,7 +131,7 @@ public:
|
||||
"msrp", "msrps", "mtqp", "mumble", "mupdate", "mvn", "news", "nfs", "ni",
|
||||
"nih", "nntp", "notes", "oid", "opaquelocktoken", "pack", "palm", "paparazzi",
|
||||
"pkcs11", "platform", "pop", "pres", "prospero", "proxy", "psyc", "query",
|
||||
"redis", "rediss", "reload", "res", "resource", "rmi", "rsync", "rtmfp",
|
||||
"redis", "rediss", "reload", "res", "target", "rmi", "rsync", "rtmfp",
|
||||
"rtmp", "rtsp", "rtsps", "rtspu", "secondlife", "service", "session", "sftp",
|
||||
"sgn", "shttp", "sieve", "sip", "sips", "skype", "smb", "sms", "smtp",
|
||||
"snews", "snmp", "soap.beep", "soap.beeps", "soldat", "spotify", "ssh",
|
||||
|
@ -130,8 +130,8 @@ public:
|
||||
auto const& m = p.get();
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
BEAST_EXPECT(p.is_complete());
|
||||
BEAST_EXPECT(m.method == "GET");
|
||||
BEAST_EXPECT(m.url == "/");
|
||||
BEAST_EXPECT(m.method() == "GET");
|
||||
BEAST_EXPECT(m.target() == "/");
|
||||
BEAST_EXPECT(m.version == 11);
|
||||
BEAST_EXPECT(m.fields["User-Agent"] == "test");
|
||||
BEAST_EXPECT(m.body == "*");
|
||||
@ -182,7 +182,7 @@ public:
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
BEAST_EXPECT(p.is_complete());
|
||||
BEAST_EXPECT(m.status == 200);
|
||||
BEAST_EXPECT(m.reason == "OK");
|
||||
BEAST_EXPECT(m.reason() == "OK");
|
||||
BEAST_EXPECT(m.version == 11);
|
||||
BEAST_EXPECT(m.fields["Server"] == "test");
|
||||
BEAST_EXPECT(m.body == "*");
|
||||
|
@ -146,8 +146,8 @@ public:
|
||||
{
|
||||
header<true, fields> m;
|
||||
m.version = 11;
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.fields.insert("User-Agent", "test");
|
||||
error_code ec;
|
||||
test::string_ostream ss{ios_};
|
||||
@ -162,7 +162,7 @@ public:
|
||||
header<false, fields> m;
|
||||
m.version = 10;
|
||||
m.status = 200;
|
||||
m.reason = "OK";
|
||||
m.reason("OK");
|
||||
m.fields.insert("Server", "test");
|
||||
m.fields.insert("Content-Length", "5");
|
||||
error_code ec;
|
||||
@ -184,7 +184,7 @@ public:
|
||||
message<false, string_body, fields> m;
|
||||
m.version = 10;
|
||||
m.status = 200;
|
||||
m.reason = "OK";
|
||||
m.reason("OK");
|
||||
m.fields.insert("Server", "test");
|
||||
m.fields.insert("Content-Length", "5");
|
||||
m.body = "*****";
|
||||
@ -203,7 +203,7 @@ public:
|
||||
message<false, string_body, fields> m;
|
||||
m.version = 11;
|
||||
m.status = 200;
|
||||
m.reason = "OK";
|
||||
m.reason("OK");
|
||||
m.fields.insert("Server", "test");
|
||||
m.fields.insert("Transfer-Encoding", "chunked");
|
||||
m.body = "*****";
|
||||
@ -236,8 +236,8 @@ public:
|
||||
message<true, fail_body, fields> m(
|
||||
std::piecewise_construct,
|
||||
std::forward_as_tuple(fc, ios_));
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.version = 10;
|
||||
m.fields.insert("User-Agent", "test");
|
||||
m.fields.insert("Content-Length", "5");
|
||||
@ -269,8 +269,8 @@ public:
|
||||
message<true, fail_body, fields> m(
|
||||
std::piecewise_construct,
|
||||
std::forward_as_tuple(fc, ios_));
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.version = 10;
|
||||
m.fields.insert("User-Agent", "test");
|
||||
m.fields.insert("Transfer-Encoding", "chunked");
|
||||
@ -304,8 +304,8 @@ public:
|
||||
message<true, fail_body, fields> m(
|
||||
std::piecewise_construct,
|
||||
std::forward_as_tuple(fc, ios_));
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.version = 10;
|
||||
m.fields.insert("User-Agent", "test");
|
||||
m.fields.insert("Transfer-Encoding", "chunked");
|
||||
@ -339,8 +339,8 @@ public:
|
||||
message<true, fail_body, fields> m(
|
||||
std::piecewise_construct,
|
||||
std::forward_as_tuple(fc, ios_));
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.version = 10;
|
||||
m.fields.insert("User-Agent", "test");
|
||||
m.fields.insert("Content-Length", "5");
|
||||
@ -369,8 +369,8 @@ public:
|
||||
message<true, fail_body, fields> m(
|
||||
std::piecewise_construct,
|
||||
std::forward_as_tuple(fc, ios_));
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.version = 10;
|
||||
m.fields.insert("User-Agent", "test");
|
||||
m.fields.insert("Content-Length", "5");
|
||||
@ -398,8 +398,8 @@ public:
|
||||
// auto content-length HTTP/1.0
|
||||
{
|
||||
message<true, string_body, fields> m;
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.version = 10;
|
||||
m.fields.insert("User-Agent", "test");
|
||||
m.body = "*";
|
||||
@ -415,8 +415,8 @@ public:
|
||||
// keep-alive HTTP/1.0
|
||||
{
|
||||
message<true, string_body, fields> m;
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.version = 10;
|
||||
m.fields.insert("User-Agent", "test");
|
||||
m.body = "*";
|
||||
@ -433,8 +433,8 @@ public:
|
||||
// upgrade HTTP/1.0
|
||||
{
|
||||
message<true, string_body, fields> m;
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.version = 10;
|
||||
m.fields.insert("User-Agent", "test");
|
||||
m.body = "*";
|
||||
@ -451,8 +451,8 @@ public:
|
||||
// no content-length HTTP/1.0
|
||||
{
|
||||
message<true, unsized_body, fields> m;
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.version = 10;
|
||||
m.fields.insert("User-Agent", "test");
|
||||
m.body = "*";
|
||||
@ -471,8 +471,8 @@ public:
|
||||
// auto content-length HTTP/1.1
|
||||
{
|
||||
message<true, string_body, fields> m;
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.version = 11;
|
||||
m.fields.insert("User-Agent", "test");
|
||||
m.body = "*";
|
||||
@ -488,8 +488,8 @@ public:
|
||||
// close HTTP/1.1
|
||||
{
|
||||
message<true, string_body, fields> m;
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.version = 11;
|
||||
m.fields.insert("User-Agent", "test");
|
||||
m.body = "*";
|
||||
@ -510,8 +510,8 @@ public:
|
||||
// upgrade HTTP/1.1
|
||||
{
|
||||
message<true, string_body, fields> m;
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.version = 11;
|
||||
m.fields.insert("User-Agent", "test");
|
||||
prepare(m, connection::upgrade);
|
||||
@ -525,8 +525,8 @@ public:
|
||||
// no content-length HTTP/1.1
|
||||
{
|
||||
message<true, unsized_body, fields> m;
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.version = 11;
|
||||
m.fields.insert("User-Agent", "test");
|
||||
m.body = "*";
|
||||
@ -550,8 +550,8 @@ public:
|
||||
{
|
||||
// Conversion to std::string via operator<<
|
||||
message<true, string_body, fields> m;
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.version = 11;
|
||||
m.fields.insert("User-Agent", "test");
|
||||
m.body = "*";
|
||||
@ -590,8 +590,8 @@ public:
|
||||
void testOstream()
|
||||
{
|
||||
message<true, string_body, fields> m;
|
||||
m.method = "GET";
|
||||
m.url = "/";
|
||||
m.method("GET");
|
||||
m.target("/");
|
||||
m.version = 11;
|
||||
m.fields.insert("User-Agent", "test");
|
||||
m.body = "*";
|
||||
@ -631,9 +631,9 @@ public:
|
||||
test::string_ostream os{ios};
|
||||
BEAST_EXPECT(handler::count() == 0);
|
||||
message<true, string_body, fields> m;
|
||||
m.method = "GET";
|
||||
m.method("GET");
|
||||
m.version = 11;
|
||||
m.url = "/";
|
||||
m.target("/");
|
||||
m.fields.insert("Content-Length", 5);
|
||||
m.body = "*****";
|
||||
async_write(os, m, handler{});
|
||||
@ -653,9 +653,9 @@ public:
|
||||
test::string_ostream is{ios};
|
||||
BEAST_EXPECT(handler::count() == 0);
|
||||
message<true, string_body, fields> m;
|
||||
m.method = "GET";
|
||||
m.method("GET");
|
||||
m.version = 11;
|
||||
m.url = "/";
|
||||
m.target("/");
|
||||
m.fields.insert("Content-Length", 5);
|
||||
m.body = "*****";
|
||||
async_write(is, m, handler{});
|
||||
|
@ -24,10 +24,10 @@ public:
|
||||
req.version = 10;
|
||||
BEAST_EXPECT(! is_upgrade(req));
|
||||
req.version = 11;
|
||||
req.method = "POST";
|
||||
req.url = "/";
|
||||
req.method("POST");
|
||||
req.target("/");
|
||||
BEAST_EXPECT(! is_upgrade(req));
|
||||
req.method = "GET";
|
||||
req.method("GET");
|
||||
req.fields.insert("Connection", "upgrade");
|
||||
BEAST_EXPECT(! is_upgrade(req));
|
||||
req.fields.insert("Upgrade", "websocket");
|
||||
|
@ -691,8 +691,8 @@ public:
|
||||
// request in message
|
||||
{
|
||||
request_type req;
|
||||
req.method = "GET";
|
||||
req.url = "/";
|
||||
req.method("GET");
|
||||
req.target("/");
|
||||
req.version = 11;
|
||||
req.fields.insert("Host", "localhost");
|
||||
req.fields.insert("Upgrade", "websocket");
|
||||
@ -705,8 +705,8 @@ public:
|
||||
}
|
||||
{
|
||||
request_type req;
|
||||
req.method = "GET";
|
||||
req.url = "/";
|
||||
req.method("GET");
|
||||
req.target("/");
|
||||
req.version = 11;
|
||||
req.fields.insert("Host", "localhost");
|
||||
req.fields.insert("Upgrade", "websocket");
|
||||
@ -723,8 +723,8 @@ public:
|
||||
// request in message, close frame in buffers
|
||||
{
|
||||
request_type req;
|
||||
req.method = "GET";
|
||||
req.url = "/";
|
||||
req.method("GET");
|
||||
req.target("/");
|
||||
req.version = 11;
|
||||
req.fields.insert("Host", "localhost");
|
||||
req.fields.insert("Upgrade", "websocket");
|
||||
@ -750,8 +750,8 @@ public:
|
||||
}
|
||||
{
|
||||
request_type req;
|
||||
req.method = "GET";
|
||||
req.url = "/";
|
||||
req.method("GET");
|
||||
req.target("/");
|
||||
req.version = 11;
|
||||
req.fields.insert("Host", "localhost");
|
||||
req.fields.insert("Upgrade", "websocket");
|
||||
@ -781,8 +781,8 @@ public:
|
||||
// request in message, close frame in stream
|
||||
{
|
||||
request_type req;
|
||||
req.method = "GET";
|
||||
req.url = "/";
|
||||
req.method("GET");
|
||||
req.target("/");
|
||||
req.version = 11;
|
||||
req.fields.insert("Host", "localhost");
|
||||
req.fields.insert("Upgrade", "websocket");
|
||||
@ -809,8 +809,8 @@ public:
|
||||
// request in message, close frame in stream and buffers
|
||||
{
|
||||
request_type req;
|
||||
req.method = "GET";
|
||||
req.url = "/";
|
||||
req.method("GET");
|
||||
req.target("/");
|
||||
req.version = 11;
|
||||
req.fields.insert("Host", "localhost");
|
||||
req.fields.insert("Upgrade", "websocket");
|
||||
|
Reference in New Issue
Block a user