mirror of
https://github.com/boostorg/beast.git
synced 2025-08-02 06:15:24 +02:00
Derive header from Fields (API Change)
This commit is contained in:
@@ -51,7 +51,7 @@ This diagram shows the inheritance relationship between header and message,
|
|||||||
along with the fields from the different partial specializations for each
|
along with the fields from the different partial specializations for each
|
||||||
possible value of `isRequest`:
|
possible value of `isRequest`:
|
||||||
|
|
||||||
[$images/message.png [width 711px] [height 424px]]
|
[$images/message.png [width 730px] [height 410px]]
|
||||||
|
|
||||||
For notational convenience, the template type aliases
|
For notational convenience, the template type aliases
|
||||||
[link beast.ref.http__request `request`] and
|
[link beast.ref.http__request `request`] and
|
||||||
@@ -126,9 +126,9 @@ objects:
|
|||||||
req.version = 11; // HTTP/1.1
|
req.version = 11; // HTTP/1.1
|
||||||
req.method(verb::get);
|
req.method(verb::get);
|
||||||
req.target("/index.htm");
|
req.target("/index.htm");
|
||||||
req.fields.insert("Accept", "text/html");
|
req.insert("Accept", "text/html");
|
||||||
req.fields.insert("Connection", "keep-alive");
|
req.insert("Connection", "keep-alive");
|
||||||
req.fields.insert("User-Agent", "Beast");
|
req.insert("User-Agent", "Beast");
|
||||||
```
|
```
|
||||||
][
|
][
|
||||||
```
|
```
|
||||||
@@ -149,8 +149,8 @@ objects:
|
|||||||
res.version = 11; // HTTP/1.1
|
res.version = 11; // HTTP/1.1
|
||||||
res.result(status::ok);
|
res.result(status::ok);
|
||||||
res.body = "Hello, world!";
|
res.body = "Hello, world!";
|
||||||
res.fields.insert("Server", "Beast");
|
res.insert("Server", "Beast");
|
||||||
res.fields.insert("Content-Length", res.body.size());
|
res.insert("Content-Length", res.body.size());
|
||||||
```
|
```
|
||||||
][
|
][
|
||||||
```
|
```
|
||||||
|
@@ -129,7 +129,7 @@ the number of octets received prior to the server closing the connection:
|
|||||||
response<string_body> res;
|
response<string_body> res;
|
||||||
res.version = 11;
|
res.version = 11;
|
||||||
res.result(status::ok);
|
res.result(status::ok);
|
||||||
res.fields.insert("Server", "Beast");
|
res.insert("Server", "Beast");
|
||||||
res.body = "Hello, world!";
|
res.body = "Hello, world!";
|
||||||
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
@@ -61,7 +61,7 @@ on the request:
|
|||||||
```
|
```
|
||||||
void decorate(websocket::request_type& req)
|
void decorate(websocket::request_type& req)
|
||||||
{
|
{
|
||||||
req.fields.insert("Sec-WebSocket-Protocol", "xmpp;ws-chat");
|
req.insert("Sec-WebSocket-Protocol", "xmpp;ws-chat");
|
||||||
}
|
}
|
||||||
...
|
...
|
||||||
ws.handshake_ex("localhost", "/", &decorate);
|
ws.handshake_ex("localhost", "/", &decorate);
|
||||||
@@ -102,7 +102,7 @@ as follows:
|
|||||||
```
|
```
|
||||||
websocket::response_type res;
|
websocket::response_type res;
|
||||||
ws.handshake(res, "localhost", "/");
|
ws.handshake(res, "localhost", "/");
|
||||||
if(! res.fields.exists("Sec-WebSocket-Protocol"))
|
if(! res.exists("Sec-WebSocket-Protocol"))
|
||||||
throw std::invalid_argument("missing subprotocols");
|
throw std::invalid_argument("missing subprotocols");
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@@ -53,7 +53,7 @@ field on the response:
|
|||||||
ws.accept_ex(
|
ws.accept_ex(
|
||||||
[](websocket::response_type& res)
|
[](websocket::response_type& res)
|
||||||
{
|
{
|
||||||
res.fields.insert("Server", "AcmeServer");
|
res.insert("Server", "AcmeServer");
|
||||||
});
|
});
|
||||||
|
|
||||||
```
|
```
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 36 KiB |
@@ -61,7 +61,7 @@ send_expect_100_continue(
|
|||||||
"DynamicBuffer requirements not met");
|
"DynamicBuffer requirements not met");
|
||||||
|
|
||||||
// Insert or replace the Expect field
|
// Insert or replace the Expect field
|
||||||
req.fields.replace("Expect", "100-continue");
|
req.replace("Expect", "100-continue");
|
||||||
|
|
||||||
// Create the serializer
|
// Create the serializer
|
||||||
auto sr = make_serializer(req);
|
auto sr = make_serializer(req);
|
||||||
@@ -130,13 +130,13 @@ receive_expect_100_continue(
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Check for the Expect field value
|
// Check for the Expect field value
|
||||||
if(parser.get().fields["Expect"] == "100-continue")
|
if(parser.get()["Expect"] == "100-continue")
|
||||||
{
|
{
|
||||||
// send 100 response
|
// send 100 response
|
||||||
response<empty_body> res;
|
response<empty_body> res;
|
||||||
res.version = 11;
|
res.version = 11;
|
||||||
res.result(status::continue_);
|
res.result(status::continue_);
|
||||||
res.fields.insert("Server", "test");
|
res.insert("Server", "test");
|
||||||
write(stream, res, ec);
|
write(stream, res, ec);
|
||||||
if(ec)
|
if(ec)
|
||||||
return;
|
return;
|
||||||
@@ -198,8 +198,8 @@ send_cgi_response(
|
|||||||
|
|
||||||
res.result(status::ok);
|
res.result(status::ok);
|
||||||
res.version = 11;
|
res.version = 11;
|
||||||
res.fields.insert("Server", "Beast");
|
res.insert("Server", "Beast");
|
||||||
res.fields.insert("Transfer-Encoding", "chunked");
|
res.insert("Transfer-Encoding", "chunked");
|
||||||
|
|
||||||
// No data yet, but we set more = true to indicate
|
// No data yet, but we set more = true to indicate
|
||||||
// that it might be coming later. Otherwise the
|
// that it might be coming later. Otherwise the
|
||||||
@@ -307,7 +307,7 @@ void do_server_head(
|
|||||||
// Set up the response, starting with the common fields
|
// Set up the response, starting with the common fields
|
||||||
response<string_body> res;
|
response<string_body> res;
|
||||||
res.version = 11;
|
res.version = 11;
|
||||||
res.fields.insert("Server", "test");
|
res.insert("Server", "test");
|
||||||
|
|
||||||
// Now handle request-specific fields
|
// Now handle request-specific fields
|
||||||
switch(req.method())
|
switch(req.method())
|
||||||
@@ -319,7 +319,7 @@ void do_server_head(
|
|||||||
// set of headers that would be sent for a GET request,
|
// set of headers that would be sent for a GET request,
|
||||||
// including the Content-Length, except for the body.
|
// including the Content-Length, except for the body.
|
||||||
res.result(status::ok);
|
res.result(status::ok);
|
||||||
res.fields.insert("Content-Length", payload.size());
|
res.insert("Content-Length", payload.size());
|
||||||
|
|
||||||
// For GET requests, we include the body
|
// For GET requests, we include the body
|
||||||
if(req.method() == verb::get)
|
if(req.method() == verb::get)
|
||||||
@@ -337,7 +337,7 @@ void do_server_head(
|
|||||||
// We return responses indicating an error if
|
// We return responses indicating an error if
|
||||||
// we do not recognize the request method.
|
// we do not recognize the request method.
|
||||||
res.result(status::bad_request);
|
res.result(status::bad_request);
|
||||||
res.fields.insert("Content-Type", "text/plain");
|
res.insert("Content-Type", "text/plain");
|
||||||
res.body = "Invalid request-method '" + req.method_string().to_string() + "'";
|
res.body = "Invalid request-method '" + req.method_string().to_string() + "'";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -397,11 +397,11 @@ do_head_request(
|
|||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.method(verb::head);
|
req.method(verb::head);
|
||||||
req.target(target);
|
req.target(target);
|
||||||
req.fields.insert("User-Agent", "test");
|
req.insert("User-Agent", "test");
|
||||||
|
|
||||||
// A client MUST send a Host header field in all HTTP/1.1 request messages.
|
// A client MUST send a Host header field in all HTTP/1.1 request messages.
|
||||||
// https://tools.ietf.org/html/rfc7230#section-5.4
|
// https://tools.ietf.org/html/rfc7230#section-5.4
|
||||||
req.fields.insert("Host", "localhost");
|
req.insert("Host", "localhost");
|
||||||
|
|
||||||
// Now send it
|
// Now send it
|
||||||
write(stream, req, ec);
|
write(stream, req, ec);
|
||||||
@@ -813,8 +813,8 @@ do_form_request(
|
|||||||
case verb::post:
|
case verb::post:
|
||||||
{
|
{
|
||||||
// If this is not a form upload then use a string_body
|
// If this is not a form upload then use a string_body
|
||||||
if( req0.get().fields["Content-Type"] != "application/x-www-form-urlencoded" &&
|
if( req0.get()["Content-Type"] != "application/x-www-form-urlencoded" &&
|
||||||
req0.get().fields["Content-Type"] != "multipart/form-data")
|
req0.get()["Content-Type"] != "multipart/form-data")
|
||||||
goto do_string_body;
|
goto do_string_body;
|
||||||
|
|
||||||
// Commit to string_body as the body type.
|
// Commit to string_body as the body type.
|
||||||
|
@@ -236,8 +236,8 @@ private:
|
|||||||
response<string_body> res;
|
response<string_body> res;
|
||||||
res.result(status::not_found);
|
res.result(status::not_found);
|
||||||
res.version = req_.version;
|
res.version = req_.version;
|
||||||
res.fields.insert("Server", "http_async_server");
|
res.insert("Server", "http_async_server");
|
||||||
res.fields.insert("Content-Type", "text/html");
|
res.insert("Content-Type", "text/html");
|
||||||
res.body = "The file '" + path + "' was not found";
|
res.body = "The file '" + path + "' was not found";
|
||||||
prepare(res);
|
prepare(res);
|
||||||
async_write(sock_, std::move(res),
|
async_write(sock_, std::move(res),
|
||||||
@@ -250,8 +250,8 @@ private:
|
|||||||
resp_type res;
|
resp_type res;
|
||||||
res.result(status::ok);
|
res.result(status::ok);
|
||||||
res.version = req_.version;
|
res.version = req_.version;
|
||||||
res.fields.insert("Server", "http_async_server");
|
res.insert("Server", "http_async_server");
|
||||||
res.fields.insert("Content-Type", mime_type(path));
|
res.insert("Content-Type", mime_type(path));
|
||||||
res.body = path;
|
res.body = path;
|
||||||
prepare(res);
|
prepare(res);
|
||||||
async_write(sock_, std::move(res),
|
async_write(sock_, std::move(res),
|
||||||
@@ -263,8 +263,8 @@ private:
|
|||||||
response<string_body> res;
|
response<string_body> res;
|
||||||
res.result(status::internal_server_error);
|
res.result(status::internal_server_error);
|
||||||
res.version = req_.version;
|
res.version = req_.version;
|
||||||
res.fields.insert("Server", "http_async_server");
|
res.insert("Server", "http_async_server");
|
||||||
res.fields.insert("Content-Type", "text/html");
|
res.insert("Content-Type", "text/html");
|
||||||
res.body =
|
res.body =
|
||||||
std::string{"An internal error occurred"} + e.what();
|
std::string{"An internal error occurred"} + e.what();
|
||||||
prepare(res);
|
prepare(res);
|
||||||
|
@@ -40,9 +40,9 @@ int main(int, char const*[])
|
|||||||
req.method(verb::get);
|
req.method(verb::get);
|
||||||
req.target("/");
|
req.target("/");
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.fields.insert("Host", host + std::string(":") +
|
req.insert("Host", host + std::string(":") +
|
||||||
boost::lexical_cast<std::string>(ep.port()));
|
boost::lexical_cast<std::string>(ep.port()));
|
||||||
req.fields.insert("User-Agent", "beast/http");
|
req.insert("User-Agent", "beast/http");
|
||||||
prepare(req);
|
prepare(req);
|
||||||
write(sock, req);
|
write(sock, req);
|
||||||
response<string_body> res;
|
response<string_body> res;
|
||||||
|
@@ -29,9 +29,9 @@ int main()
|
|||||||
req.method(beast::http::verb::get);
|
req.method(beast::http::verb::get);
|
||||||
req.target("/");
|
req.target("/");
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.fields.replace("Host", host + ":" +
|
req.replace("Host", host + ":" +
|
||||||
boost::lexical_cast<std::string>(sock.remote_endpoint().port()));
|
boost::lexical_cast<std::string>(sock.remote_endpoint().port()));
|
||||||
req.fields.replace("User-Agent", "Beast");
|
req.replace("User-Agent", "Beast");
|
||||||
beast::http::prepare(req);
|
beast::http::prepare(req);
|
||||||
beast::http::write(sock, req);
|
beast::http::write(sock, req);
|
||||||
|
|
||||||
|
@@ -166,8 +166,8 @@ private:
|
|||||||
response<string_body> res;
|
response<string_body> res;
|
||||||
res.result(status::not_found);
|
res.result(status::not_found);
|
||||||
res.version = req.version;
|
res.version = req.version;
|
||||||
res.fields.insert("Server", "http_sync_server");
|
res.insert("Server", "http_sync_server");
|
||||||
res.fields.insert("Content-Type", "text/html");
|
res.insert("Content-Type", "text/html");
|
||||||
res.body = "The file '" + path + "' was not found";
|
res.body = "The file '" + path + "' was not found";
|
||||||
prepare(res);
|
prepare(res);
|
||||||
write(sock, res, ec);
|
write(sock, res, ec);
|
||||||
@@ -181,8 +181,8 @@ private:
|
|||||||
res.result(status::ok);
|
res.result(status::ok);
|
||||||
res.reason("OK");
|
res.reason("OK");
|
||||||
res.version = req.version;
|
res.version = req.version;
|
||||||
res.fields.insert("Server", "http_sync_server");
|
res.insert("Server", "http_sync_server");
|
||||||
res.fields.insert("Content-Type", mime_type(path));
|
res.insert("Content-Type", mime_type(path));
|
||||||
res.body = path;
|
res.body = path;
|
||||||
prepare(res);
|
prepare(res);
|
||||||
write(sock, res, ec);
|
write(sock, res, ec);
|
||||||
@@ -195,8 +195,8 @@ private:
|
|||||||
res.result(status::internal_server_error);
|
res.result(status::internal_server_error);
|
||||||
res.reason("Internal Error");
|
res.reason("Internal Error");
|
||||||
res.version = req.version;
|
res.version = req.version;
|
||||||
res.fields.insert("Server", "http_sync_server");
|
res.insert("Server", "http_sync_server");
|
||||||
res.fields.insert("Content-Type", "text/html");
|
res.insert("Content-Type", "text/html");
|
||||||
res.body =
|
res.body =
|
||||||
std::string{"An internal error occurred: "} + e.what();
|
std::string{"An internal error occurred: "} + e.what();
|
||||||
prepare(res);
|
prepare(res);
|
||||||
|
@@ -38,9 +38,9 @@ int main()
|
|||||||
req.method(beast::http::verb::get);
|
req.method(beast::http::verb::get);
|
||||||
req.target("/");
|
req.target("/");
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.fields.insert("Host", host + ":" +
|
req.insert("Host", host + ":" +
|
||||||
boost::lexical_cast<std::string>(sock.remote_endpoint().port()));
|
boost::lexical_cast<std::string>(sock.remote_endpoint().port()));
|
||||||
req.fields.insert("User-Agent", "Beast");
|
req.insert("User-Agent", "Beast");
|
||||||
beast::http::prepare(req);
|
beast::http::prepare(req);
|
||||||
beast::http::write(stream, req);
|
beast::http::write(stream, req);
|
||||||
|
|
||||||
|
@@ -263,7 +263,7 @@ private:
|
|||||||
d.ws.async_accept_ex(
|
d.ws.async_accept_ex(
|
||||||
[](beast::websocket::response_type& res)
|
[](beast::websocket::response_type& res)
|
||||||
{
|
{
|
||||||
res.fields.insert(
|
res.insert(
|
||||||
"Server", "async_echo_server");
|
"Server", "async_echo_server");
|
||||||
},
|
},
|
||||||
std::move(*this));
|
std::move(*this));
|
||||||
|
@@ -274,7 +274,7 @@ private:
|
|||||||
ws.accept_ex(
|
ws.accept_ex(
|
||||||
[](beast::websocket::response_type& res)
|
[](beast::websocket::response_type& res)
|
||||||
{
|
{
|
||||||
res.fields.insert(
|
res.insert(
|
||||||
"Server", "sync_echo_server");
|
"Server", "sync_echo_server");
|
||||||
},
|
},
|
||||||
ec);
|
ec);
|
||||||
|
@@ -268,54 +268,14 @@ public:
|
|||||||
boost::lexical_cast<std::string>(value));
|
boost::lexical_cast<std::string>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if BEAST_DOXYGEN
|
protected:
|
||||||
private:
|
// for header
|
||||||
#endif
|
string_view method_impl() const;
|
||||||
|
string_view target_impl() const;
|
||||||
string_view
|
string_view reason_impl() const;
|
||||||
method_impl() const
|
void method_impl(string_view s);
|
||||||
{
|
void target_impl(string_view s);
|
||||||
return (*this)[":method"];
|
void reason_impl(string_view s);
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
method_impl(string_view s)
|
|
||||||
{
|
|
||||||
if(s.empty())
|
|
||||||
this->erase(":method");
|
|
||||||
else
|
|
||||||
this->replace(":method", s);
|
|
||||||
}
|
|
||||||
|
|
||||||
string_view
|
|
||||||
target_impl() const
|
|
||||||
{
|
|
||||||
return (*this)[":target"];
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
target_impl(string_view s)
|
|
||||||
{
|
|
||||||
if(s.empty())
|
|
||||||
this->erase(":target");
|
|
||||||
else
|
|
||||||
return this->replace(":target", s);
|
|
||||||
}
|
|
||||||
|
|
||||||
string_view
|
|
||||||
reason_impl() const
|
|
||||||
{
|
|
||||||
return (*this)[":reason"];
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
reason_impl(string_view s)
|
|
||||||
{
|
|
||||||
if(s.empty())
|
|
||||||
this->erase(":reason");
|
|
||||||
else
|
|
||||||
this->replace(":reason", s);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct element
|
struct element
|
||||||
|
@@ -26,6 +26,71 @@ basic_fields<Allocator>::
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
template<class Allocator>
|
||||||
|
inline
|
||||||
|
string_view
|
||||||
|
basic_fields<Allocator>::
|
||||||
|
method_impl() const
|
||||||
|
{
|
||||||
|
return (*this)[":method"];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Allocator>
|
||||||
|
inline
|
||||||
|
string_view
|
||||||
|
basic_fields<Allocator>::
|
||||||
|
target_impl() const
|
||||||
|
{
|
||||||
|
return (*this)[":target"];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Allocator>
|
||||||
|
inline
|
||||||
|
string_view
|
||||||
|
basic_fields<Allocator>::
|
||||||
|
reason_impl() const
|
||||||
|
{
|
||||||
|
return (*this)[":reason"];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Allocator>
|
||||||
|
inline
|
||||||
|
void
|
||||||
|
basic_fields<Allocator>::
|
||||||
|
method_impl(string_view s)
|
||||||
|
{
|
||||||
|
if(s.empty())
|
||||||
|
this->erase(":method");
|
||||||
|
else
|
||||||
|
this->replace(":method", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Allocator>
|
||||||
|
inline
|
||||||
|
void
|
||||||
|
basic_fields<Allocator>::
|
||||||
|
target_impl(string_view s)
|
||||||
|
{
|
||||||
|
if(s.empty())
|
||||||
|
this->erase(":target");
|
||||||
|
else
|
||||||
|
return this->replace(":target", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Allocator>
|
||||||
|
inline
|
||||||
|
void
|
||||||
|
basic_fields<Allocator>::
|
||||||
|
reason_impl(string_view s)
|
||||||
|
{
|
||||||
|
if(s.empty())
|
||||||
|
this->erase(":reason");
|
||||||
|
else
|
||||||
|
this->replace(":reason", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
template<class Allocator>
|
template<class Allocator>
|
||||||
class basic_fields<Allocator>::
|
class basic_fields<Allocator>::
|
||||||
const_iterator
|
const_iterator
|
||||||
|
@@ -30,7 +30,7 @@ get_method_string() const
|
|||||||
{
|
{
|
||||||
if(method_ != verb::unknown)
|
if(method_ != verb::unknown)
|
||||||
return to_string(method_);
|
return to_string(method_);
|
||||||
return fields.method_impl();
|
return this->method_impl();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Fields>
|
template<class Fields>
|
||||||
@@ -43,7 +43,7 @@ set_method(verb v)
|
|||||||
BOOST_THROW_EXCEPTION(
|
BOOST_THROW_EXCEPTION(
|
||||||
std::invalid_argument{"unknown verb"});
|
std::invalid_argument{"unknown verb"});
|
||||||
method_ = v;
|
method_ = v;
|
||||||
fields.method_impl({});
|
this->method_impl({});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Fields>
|
template<class Fields>
|
||||||
@@ -54,9 +54,9 @@ set_method(string_view s)
|
|||||||
{
|
{
|
||||||
method_ = string_to_verb(s);
|
method_ = string_to_verb(s);
|
||||||
if(method_ != verb::unknown)
|
if(method_ != verb::unknown)
|
||||||
fields.method_impl({});
|
this->method_impl({});
|
||||||
else
|
else
|
||||||
fields.method_impl(s);
|
this->method_impl(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Fields>
|
template<class Fields>
|
||||||
@@ -65,7 +65,7 @@ string_view
|
|||||||
header<false, Fields>::
|
header<false, Fields>::
|
||||||
get_reason() const
|
get_reason() const
|
||||||
{
|
{
|
||||||
auto const s = fields.reason_impl();
|
auto const s = this->reason_impl();
|
||||||
if(! s.empty())
|
if(! s.empty())
|
||||||
return s;
|
return s;
|
||||||
return obsolete_reason(result_);
|
return obsolete_reason(result_);
|
||||||
@@ -74,25 +74,29 @@ get_reason() const
|
|||||||
template<class Fields>
|
template<class Fields>
|
||||||
void
|
void
|
||||||
swap(
|
swap(
|
||||||
header<true, Fields>& m1,
|
header<true, Fields>& h1,
|
||||||
header<true, Fields>& m2)
|
header<true, Fields>& h2)
|
||||||
{
|
{
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap(m1.version, m2.version);
|
swap(
|
||||||
swap(m1.fields, m2.fields);
|
static_cast<Fields&>(h1),
|
||||||
swap(m1.method_, m2.method_);
|
static_cast<Fields&>(h2));
|
||||||
|
swap(h1.version, h2.version);
|
||||||
|
swap(h1.method_, h2.method_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Fields>
|
template<class Fields>
|
||||||
void
|
void
|
||||||
swap(
|
swap(
|
||||||
header<false, Fields>& a,
|
header<false, Fields>& h1,
|
||||||
header<false, Fields>& b)
|
header<false, Fields>& h2)
|
||||||
{
|
{
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap(a.version, b.version);
|
swap(
|
||||||
swap(a.fields, b.fields);
|
static_cast<Fields&>(h1),
|
||||||
swap(a.result_, b.result_);
|
static_cast<Fields&>(h2));
|
||||||
|
swap(h1.version, h2.version);
|
||||||
|
swap(h1.result_, h2.result_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool isRequest, class Body, class Fields>
|
template<bool isRequest, class Body, class Fields>
|
||||||
@@ -113,11 +117,11 @@ is_keep_alive(header<isRequest, Fields> const& msg)
|
|||||||
BOOST_ASSERT(msg.version == 10 || msg.version == 11);
|
BOOST_ASSERT(msg.version == 10 || msg.version == 11);
|
||||||
if(msg.version == 11)
|
if(msg.version == 11)
|
||||||
{
|
{
|
||||||
if(token_list{msg.fields["Connection"]}.exists("close"))
|
if(token_list{msg["Connection"]}.exists("close"))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(token_list{msg.fields["Connection"]}.exists("keep-alive"))
|
if(token_list{msg["Connection"]}.exists("keep-alive"))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -129,7 +133,7 @@ is_upgrade(header<isRequest, Fields> const& msg)
|
|||||||
BOOST_ASSERT(msg.version == 10 || msg.version == 11);
|
BOOST_ASSERT(msg.version == 10 || msg.version == 11);
|
||||||
if(msg.version == 10)
|
if(msg.version == 10)
|
||||||
return false;
|
return false;
|
||||||
if(token_list{msg.fields["Connection"]}.exists("upgrade"))
|
if(token_list{msg["Connection"]}.exists("upgrade"))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -219,15 +223,15 @@ prepare(message<isRequest, Body, Fields>& msg,
|
|||||||
detail::prepare_options(pi, msg,
|
detail::prepare_options(pi, msg,
|
||||||
std::forward<Options>(options)...);
|
std::forward<Options>(options)...);
|
||||||
|
|
||||||
if(msg.fields.exists("Connection"))
|
if(msg.exists("Connection"))
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument{
|
BOOST_THROW_EXCEPTION(std::invalid_argument{
|
||||||
"prepare called with Connection field set"});
|
"prepare called with Connection field set"});
|
||||||
|
|
||||||
if(msg.fields.exists("Content-Length"))
|
if(msg.exists("Content-Length"))
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument{
|
BOOST_THROW_EXCEPTION(std::invalid_argument{
|
||||||
"prepare called with Content-Length field set"});
|
"prepare called with Content-Length field set"});
|
||||||
|
|
||||||
if(token_list{msg.fields["Transfer-Encoding"]}.exists("chunked"))
|
if(token_list{msg["Transfer-Encoding"]}.exists("chunked"))
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument{
|
BOOST_THROW_EXCEPTION(std::invalid_argument{
|
||||||
"prepare called with Transfer-Encoding: chunked set"});
|
"prepare called with Transfer-Encoding: chunked set"});
|
||||||
|
|
||||||
@@ -245,7 +249,7 @@ prepare(message<isRequest, Body, Fields>& msg,
|
|||||||
if(*pi.content_length > 0 ||
|
if(*pi.content_length > 0 ||
|
||||||
msg.method() == verb::post)
|
msg.method() == verb::post)
|
||||||
{
|
{
|
||||||
msg.fields.insert(
|
msg.insert(
|
||||||
"Content-Length", *pi.content_length);
|
"Content-Length", *pi.content_length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -258,7 +262,7 @@ prepare(message<isRequest, Body, Fields>& msg,
|
|||||||
msg.result() != status::no_content &&
|
msg.result() != status::no_content &&
|
||||||
msg.result() != status::not_modified)
|
msg.result() != status::not_modified)
|
||||||
{
|
{
|
||||||
msg.fields.insert(
|
msg.insert(
|
||||||
"Content-Length", *pi.content_length);
|
"Content-Length", *pi.content_length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -267,39 +271,39 @@ prepare(message<isRequest, Body, Fields>& msg,
|
|||||||
}
|
}
|
||||||
else if(msg.version >= 11)
|
else if(msg.version >= 11)
|
||||||
{
|
{
|
||||||
msg.fields.insert("Transfer-Encoding", "chunked");
|
msg.insert("Transfer-Encoding", "chunked");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto const content_length =
|
auto const content_length =
|
||||||
msg.fields.exists("Content-Length");
|
msg.exists("Content-Length");
|
||||||
|
|
||||||
if(pi.connection_value)
|
if(pi.connection_value)
|
||||||
{
|
{
|
||||||
switch(*pi.connection_value)
|
switch(*pi.connection_value)
|
||||||
{
|
{
|
||||||
case connection::upgrade:
|
case connection::upgrade:
|
||||||
msg.fields.insert("Connection", "upgrade");
|
msg.insert("Connection", "upgrade");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case connection::keep_alive:
|
case connection::keep_alive:
|
||||||
if(msg.version < 11)
|
if(msg.version < 11)
|
||||||
{
|
{
|
||||||
if(content_length)
|
if(content_length)
|
||||||
msg.fields.insert("Connection", "keep-alive");
|
msg.insert("Connection", "keep-alive");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case connection::close:
|
case connection::close:
|
||||||
if(msg.version >= 11)
|
if(msg.version >= 11)
|
||||||
msg.fields.insert("Connection", "close");
|
msg.insert("Connection", "close");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// rfc7230 6.7.
|
// rfc7230 6.7.
|
||||||
if(msg.version < 11 && token_list{
|
if(msg.version < 11 && token_list{
|
||||||
msg.fields["Connection"]}.exists("upgrade"))
|
msg["Connection"]}.exists("upgrade"))
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument{
|
BOOST_THROW_EXCEPTION(std::invalid_argument{
|
||||||
"invalid version for Connection: upgrade"});
|
"invalid version for Connection: upgrade"});
|
||||||
}
|
}
|
||||||
|
@@ -94,12 +94,12 @@ get(error_code& ec, Visit&& visit)
|
|||||||
case do_construct:
|
case do_construct:
|
||||||
{
|
{
|
||||||
chunked_ = token_list{
|
chunked_ = token_list{
|
||||||
m_.fields["Transfer-Encoding"]}.exists("chunked");
|
m_["Transfer-Encoding"]}.exists("chunked");
|
||||||
close_ = token_list{m_.fields["Connection"]}.exists("close") ||
|
close_ = token_list{m_["Connection"]}.exists("close") ||
|
||||||
(m_.version < 11 && ! m_.fields.exists("Content-Length"));
|
(m_.version < 11 && ! m_.exists("Content-Length"));
|
||||||
auto os = ostream(b_);
|
auto os = ostream(b_);
|
||||||
detail::write_start_line(os, m_);
|
detail::write_start_line(os, m_);
|
||||||
detail::write_fields(os, m_.fields);
|
detail::write_fields(os, m_);
|
||||||
os << "\r\n";
|
os << "\r\n";
|
||||||
if(chunked_)
|
if(chunked_)
|
||||||
goto go_init_c;
|
goto go_init_c;
|
||||||
|
@@ -828,7 +828,7 @@ operator<<(std::ostream& os,
|
|||||||
header<isRequest, Fields> const& msg)
|
header<isRequest, Fields> const& msg)
|
||||||
{
|
{
|
||||||
detail::write_start_line(os, msg);
|
detail::write_start_line(os, msg);
|
||||||
detail::write_fields(os, msg.fields);
|
detail::write_fields(os, msg);
|
||||||
os << "\r\n";
|
os << "\r\n";
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
@@ -45,7 +45,7 @@ template<bool isRequest, class Fields = fields>
|
|||||||
struct header;
|
struct header;
|
||||||
|
|
||||||
template<class Fields>
|
template<class Fields>
|
||||||
struct header<true, Fields>
|
struct header<true, Fields> : Fields
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/// Indicates if the header is a request or response.
|
/// Indicates if the header is a request or response.
|
||||||
@@ -59,6 +59,17 @@ struct header<true, Fields>
|
|||||||
/// The type representing the fields.
|
/// The type representing the fields.
|
||||||
using fields_type = Fields;
|
using fields_type = Fields;
|
||||||
|
|
||||||
|
/** The HTTP-version.
|
||||||
|
|
||||||
|
This holds both the major and minor version numbers,
|
||||||
|
using these formulas:
|
||||||
|
@code
|
||||||
|
int major = version / 10;
|
||||||
|
int minor = version % 10;
|
||||||
|
@endcode
|
||||||
|
*/
|
||||||
|
int version;
|
||||||
|
|
||||||
/// Default constructor
|
/// Default constructor
|
||||||
header() = default;
|
header() = default;
|
||||||
|
|
||||||
@@ -96,25 +107,11 @@ struct header<true, Fields>
|
|||||||
header>::value>::type>
|
header>::value>::type>
|
||||||
explicit
|
explicit
|
||||||
header(Arg1&& arg1, ArgN&&... argn)
|
header(Arg1&& arg1, ArgN&&... argn)
|
||||||
: fields(std::forward<Arg1>(arg1),
|
: Fields(std::forward<Arg1>(arg1),
|
||||||
std::forward<ArgN>(argn)...)
|
std::forward<ArgN>(argn)...)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The HTTP-version.
|
|
||||||
|
|
||||||
This holds both the major and minor version numbers,
|
|
||||||
using these formulas:
|
|
||||||
@code
|
|
||||||
int major = version / 10;
|
|
||||||
int minor = version % 10;
|
|
||||||
@endcode
|
|
||||||
*/
|
|
||||||
int version;
|
|
||||||
|
|
||||||
/// The HTTP field values.
|
|
||||||
fields_type fields;
|
|
||||||
|
|
||||||
/** Return the request-method verb.
|
/** Return the request-method verb.
|
||||||
|
|
||||||
If the request-method is not one of the recognized verbs,
|
If the request-method is not one of the recognized verbs,
|
||||||
@@ -181,7 +178,7 @@ struct header<true, Fields>
|
|||||||
string_view
|
string_view
|
||||||
target() const
|
target() const
|
||||||
{
|
{
|
||||||
return fields.target_impl();
|
return this->target_impl();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set the request-target string.
|
/** Set the request-target string.
|
||||||
@@ -193,7 +190,7 @@ struct header<true, Fields>
|
|||||||
void
|
void
|
||||||
target(string_view s)
|
target(string_view s)
|
||||||
{
|
{
|
||||||
fields.target_impl(s);
|
this->target_impl(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -230,7 +227,7 @@ private:
|
|||||||
@li Invoke algorithms which operate on the header only.
|
@li Invoke algorithms which operate on the header only.
|
||||||
*/
|
*/
|
||||||
template<class Fields>
|
template<class Fields>
|
||||||
struct header<false, Fields>
|
struct header<false, Fields> : Fields
|
||||||
{
|
{
|
||||||
/// Indicates if the header is a request or response.
|
/// Indicates if the header is a request or response.
|
||||||
static bool constexpr is_request = false;
|
static bool constexpr is_request = false;
|
||||||
@@ -249,9 +246,6 @@ struct header<false, Fields>
|
|||||||
*/
|
*/
|
||||||
int version;
|
int version;
|
||||||
|
|
||||||
/// The HTTP field values.
|
|
||||||
fields_type fields;
|
|
||||||
|
|
||||||
/// Default constructor.
|
/// Default constructor.
|
||||||
header() = default;
|
header() = default;
|
||||||
|
|
||||||
@@ -283,7 +277,7 @@ struct header<false, Fields>
|
|||||||
header>::value>::type>
|
header>::value>::type>
|
||||||
explicit
|
explicit
|
||||||
header(Arg1&& arg1, ArgN&&... argn)
|
header(Arg1&& arg1, ArgN&&... argn)
|
||||||
: fields(std::forward<Arg1>(arg1),
|
: Fields(std::forward<Arg1>(arg1),
|
||||||
std::forward<ArgN>(argn)...)
|
std::forward<ArgN>(argn)...)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -379,7 +373,7 @@ struct header<false, Fields>
|
|||||||
void
|
void
|
||||||
reason(string_view s)
|
reason(string_view s)
|
||||||
{
|
{
|
||||||
fields.reason_impl(s);
|
this->reason_impl(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -208,7 +208,7 @@ private:
|
|||||||
string_view value,
|
string_view value,
|
||||||
error_code&)
|
error_code&)
|
||||||
{
|
{
|
||||||
m_.fields.insert(name, value);
|
m_.insert(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -153,8 +153,7 @@ operator()(error_code ec, bool again)
|
|||||||
ec = error::handshake_failed;
|
ec = error::handshake_failed;
|
||||||
if(! ec)
|
if(! ec)
|
||||||
{
|
{
|
||||||
pmd_read(
|
pmd_read(d.ws.pmd_config_, d.res);
|
||||||
d.ws.pmd_config_, d.res.fields);
|
|
||||||
d.ws.open(detail::role_type::server);
|
d.ws.open(detail::role_type::server);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@@ -132,8 +132,7 @@ operator()(error_code ec, bool again)
|
|||||||
// VFALCO Do we need the ability to move
|
// VFALCO Do we need the ability to move
|
||||||
// a message on the async_write?
|
// a message on the async_write?
|
||||||
//
|
//
|
||||||
pmd_read(
|
pmd_read(d.ws.pmd_config_, d.req);
|
||||||
d.ws.pmd_config_, d.req.fields);
|
|
||||||
http::async_write(d.ws.stream_,
|
http::async_write(d.ws.stream_,
|
||||||
d.req, std::move(*this));
|
d.req, std::move(*this));
|
||||||
// TODO We don't need d.req now. Figure
|
// TODO We don't need d.req now. Figure
|
||||||
|
@@ -23,9 +23,9 @@ is_upgrade(http::header<true, Fields> const& req)
|
|||||||
return false;
|
return false;
|
||||||
if(! http::is_upgrade(req))
|
if(! http::is_upgrade(req))
|
||||||
return false;
|
return false;
|
||||||
if(! http::token_list{req.fields["Upgrade"]}.exists("websocket"))
|
if(! http::token_list{req["Upgrade"]}.exists("websocket"))
|
||||||
return false;
|
return false;
|
||||||
if(! req.fields.exists("Sec-WebSocket-Version"))
|
if(! req.exists("Sec-WebSocket-Version"))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -117,7 +117,7 @@ do_accept(http::header<true, Fields> const& req,
|
|||||||
// teardown if Connection: close.
|
// teardown if Connection: close.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pmd_read(pmd_config_, req.fields);
|
pmd_read(pmd_config_, req);
|
||||||
open(detail::role_type::server);
|
open(detail::role_type::server);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ do_handshake(response_type* res_p,
|
|||||||
{
|
{
|
||||||
auto const req = build_request(
|
auto const req = build_request(
|
||||||
key, host, target, decorator);
|
key, host, target, decorator);
|
||||||
pmd_read(pmd_config_, req.fields);
|
pmd_read(pmd_config_, req);
|
||||||
http::write(stream_, req, ec);
|
http::write(stream_, req, ec);
|
||||||
}
|
}
|
||||||
if(ec)
|
if(ec)
|
||||||
@@ -163,12 +163,12 @@ build_request(detail::sec_ws_key_type& key,
|
|||||||
req.target(target);
|
req.target(target);
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.method(http::verb::get);
|
req.method(http::verb::get);
|
||||||
req.fields.insert("Host", host);
|
req.insert("Host", host);
|
||||||
req.fields.insert("Upgrade", "websocket");
|
req.insert("Upgrade", "websocket");
|
||||||
req.fields.insert("Connection", "upgrade");
|
req.insert("Connection", "upgrade");
|
||||||
detail::make_sec_ws_key(key, maskgen_);
|
detail::make_sec_ws_key(key, maskgen_);
|
||||||
req.fields.insert("Sec-WebSocket-Key", key);
|
req.insert("Sec-WebSocket-Key", key);
|
||||||
req.fields.insert("Sec-WebSocket-Version", "13");
|
req.insert("Sec-WebSocket-Version", "13");
|
||||||
if(pmd_opts_.client_enable)
|
if(pmd_opts_.client_enable)
|
||||||
{
|
{
|
||||||
detail::pmd_offer config;
|
detail::pmd_offer config;
|
||||||
@@ -181,14 +181,13 @@ build_request(detail::sec_ws_key_type& key,
|
|||||||
pmd_opts_.server_no_context_takeover;
|
pmd_opts_.server_no_context_takeover;
|
||||||
config.client_no_context_takeover =
|
config.client_no_context_takeover =
|
||||||
pmd_opts_.client_no_context_takeover;
|
pmd_opts_.client_no_context_takeover;
|
||||||
detail::pmd_write(
|
detail::pmd_write(req, config);
|
||||||
req.fields, config);
|
|
||||||
}
|
}
|
||||||
decorator(req);
|
decorator(req);
|
||||||
if(! req.fields.exists("User-Agent"))
|
if(! req.exists("User-Agent"))
|
||||||
{
|
{
|
||||||
static_string<20> s(BEAST_VERSION_STRING);
|
static_string<20> s(BEAST_VERSION_STRING);
|
||||||
req.fields.insert("User-Agent", s);
|
req.insert("User-Agent", s);
|
||||||
}
|
}
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
@@ -204,10 +203,10 @@ build_response(http::header<true, Fields> const& req,
|
|||||||
[&decorator](response_type& res)
|
[&decorator](response_type& res)
|
||||||
{
|
{
|
||||||
decorator(res);
|
decorator(res);
|
||||||
if(! res.fields.exists("Server"))
|
if(! res.exists("Server"))
|
||||||
{
|
{
|
||||||
static_string<20> s(BEAST_VERSION_STRING);
|
static_string<20> s(BEAST_VERSION_STRING);
|
||||||
res.fields.insert("Server", s);
|
res.insert("Server", s);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
auto err =
|
auto err =
|
||||||
@@ -227,18 +226,18 @@ build_response(http::header<true, Fields> const& req,
|
|||||||
return err("Wrong method");
|
return err("Wrong method");
|
||||||
if(! is_upgrade(req))
|
if(! is_upgrade(req))
|
||||||
return err("Expected Upgrade request");
|
return err("Expected Upgrade request");
|
||||||
if(! req.fields.exists("Host"))
|
if(! req.exists("Host"))
|
||||||
return err("Missing Host");
|
return err("Missing Host");
|
||||||
if(! req.fields.exists("Sec-WebSocket-Key"))
|
if(! req.exists("Sec-WebSocket-Key"))
|
||||||
return err("Missing Sec-WebSocket-Key");
|
return err("Missing Sec-WebSocket-Key");
|
||||||
if(! http::token_list{req.fields["Upgrade"]}.exists("websocket"))
|
if(! http::token_list{req["Upgrade"]}.exists("websocket"))
|
||||||
return err("Missing websocket Upgrade token");
|
return err("Missing websocket Upgrade token");
|
||||||
auto const key = req.fields["Sec-WebSocket-Key"];
|
auto const key = req["Sec-WebSocket-Key"];
|
||||||
if(key.size() > detail::sec_ws_key_type::max_size_n)
|
if(key.size() > detail::sec_ws_key_type::max_size_n)
|
||||||
return err("Invalid Sec-WebSocket-Key");
|
return err("Invalid Sec-WebSocket-Key");
|
||||||
{
|
{
|
||||||
auto const version =
|
auto const version =
|
||||||
req.fields["Sec-WebSocket-Version"];
|
req["Sec-WebSocket-Version"];
|
||||||
if(version.empty())
|
if(version.empty())
|
||||||
return err("Missing Sec-WebSocket-Version");
|
return err("Missing Sec-WebSocket-Version");
|
||||||
if(version != "13")
|
if(version != "13")
|
||||||
@@ -246,7 +245,7 @@ build_response(http::header<true, Fields> const& req,
|
|||||||
response_type res;
|
response_type res;
|
||||||
res.result(http::status::upgrade_required);
|
res.result(http::status::upgrade_required);
|
||||||
res.version = req.version;
|
res.version = req.version;
|
||||||
res.fields.insert("Sec-WebSocket-Version", "13");
|
res.insert("Sec-WebSocket-Version", "13");
|
||||||
prepare(res);
|
prepare(res);
|
||||||
decorate(res);
|
decorate(res);
|
||||||
return res;
|
return res;
|
||||||
@@ -257,18 +256,17 @@ build_response(http::header<true, Fields> const& req,
|
|||||||
{
|
{
|
||||||
detail::pmd_offer offer;
|
detail::pmd_offer offer;
|
||||||
detail::pmd_offer unused;
|
detail::pmd_offer unused;
|
||||||
pmd_read(offer, req.fields);
|
pmd_read(offer, req);
|
||||||
pmd_negotiate(
|
pmd_negotiate(res, unused, offer, pmd_opts_);
|
||||||
res.fields, unused, offer, pmd_opts_);
|
|
||||||
}
|
}
|
||||||
res.result(http::status::switching_protocols);
|
res.result(http::status::switching_protocols);
|
||||||
res.version = req.version;
|
res.version = req.version;
|
||||||
res.fields.insert("Upgrade", "websocket");
|
res.insert("Upgrade", "websocket");
|
||||||
res.fields.insert("Connection", "upgrade");
|
res.insert("Connection", "upgrade");
|
||||||
{
|
{
|
||||||
detail::sec_ws_accept_type accept;
|
detail::sec_ws_accept_type accept;
|
||||||
detail::make_sec_ws_accept(accept, key);
|
detail::make_sec_ws_accept(accept, key);
|
||||||
res.fields.insert("Sec-WebSocket-Accept", accept);
|
res.insert("Sec-WebSocket-Accept", accept);
|
||||||
}
|
}
|
||||||
decorate(res);
|
decorate(res);
|
||||||
return res;
|
return res;
|
||||||
@@ -288,14 +286,14 @@ do_response(http::header<false> const& res,
|
|||||||
return false;
|
return false;
|
||||||
if(! is_upgrade(res))
|
if(! is_upgrade(res))
|
||||||
return false;
|
return false;
|
||||||
if(! http::token_list{res.fields["Upgrade"]}.exists("websocket"))
|
if(! http::token_list{res["Upgrade"]}.exists("websocket"))
|
||||||
return false;
|
return false;
|
||||||
if(! res.fields.exists("Sec-WebSocket-Accept"))
|
if(! res.exists("Sec-WebSocket-Accept"))
|
||||||
return false;
|
return false;
|
||||||
detail::sec_ws_accept_type accept;
|
detail::sec_ws_accept_type accept;
|
||||||
detail::make_sec_ws_accept(accept, key);
|
detail::make_sec_ws_accept(accept, key);
|
||||||
if(accept.compare(
|
if(accept.compare(
|
||||||
res.fields["Sec-WebSocket-Accept"]) != 0)
|
res["Sec-WebSocket-Accept"]) != 0)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}();
|
}();
|
||||||
@@ -305,7 +303,7 @@ do_response(http::header<false> const& res,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
detail::pmd_offer offer;
|
detail::pmd_offer offer;
|
||||||
pmd_read(offer, res.fields);
|
pmd_read(offer, res);
|
||||||
// VFALCO see if offer satisfies pmd_config_,
|
// VFALCO see if offer satisfies pmd_config_,
|
||||||
// return an error if not.
|
// return an error if not.
|
||||||
pmd_config_ = offer; // overwrite for now
|
pmd_config_ = offer; // overwrite for now
|
||||||
|
@@ -1563,7 +1563,7 @@ public:
|
|||||||
ws.handshake("localhost", "/",
|
ws.handshake("localhost", "/",
|
||||||
[](request_type& req)
|
[](request_type& req)
|
||||||
{
|
{
|
||||||
req.fields.insert("User-Agent", "Beast");
|
req.insert("User-Agent", "Beast");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
@@ -1625,7 +1625,7 @@ public:
|
|||||||
ws.handshake(res, "localhost", "/",
|
ws.handshake(res, "localhost", "/",
|
||||||
[](request_type& req)
|
[](request_type& req)
|
||||||
{
|
{
|
||||||
req.fields.insert("User-Agent", "Beast");
|
req.insert("User-Agent", "Beast");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
@@ -1771,7 +1771,7 @@ public:
|
|||||||
ws.handshake("localhost", "/",
|
ws.handshake("localhost", "/",
|
||||||
[](request_type& req)
|
[](request_type& req)
|
||||||
{
|
{
|
||||||
req.fields.insert("User-Agent", "Beast");
|
req.insert("User-Agent", "Beast");
|
||||||
},
|
},
|
||||||
ec);
|
ec);
|
||||||
if(ec)
|
if(ec)
|
||||||
@@ -1833,7 +1833,7 @@ public:
|
|||||||
ws.handshake(res, "localhost", "/",
|
ws.handshake(res, "localhost", "/",
|
||||||
[](request_type& req)
|
[](request_type& req)
|
||||||
{
|
{
|
||||||
req.fields.insert("User-Agent", "Beast");
|
req.insert("User-Agent", "Beast");
|
||||||
},
|
},
|
||||||
ec);
|
ec);
|
||||||
if(ec)
|
if(ec)
|
||||||
|
@@ -66,11 +66,11 @@ public:
|
|||||||
[&](yield_context)
|
[&](yield_context)
|
||||||
{
|
{
|
||||||
flat_buffer buffer;
|
flat_buffer buffer;
|
||||||
request<string_body, fields> req;
|
request<string_body> req;
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.method("POST");
|
req.method("POST");
|
||||||
req.target("/");
|
req.target("/");
|
||||||
req.fields.insert("User-Agent", "test");
|
req.insert("User-Agent", "test");
|
||||||
req.body = "Hello, world!";
|
req.body = "Hello, world!";
|
||||||
prepare(req);
|
prepare(req);
|
||||||
|
|
||||||
@@ -99,11 +99,11 @@ public:
|
|||||||
void
|
void
|
||||||
doRelay()
|
doRelay()
|
||||||
{
|
{
|
||||||
request<string_body, fields> req;
|
request<string_body> req;
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.method("POST");
|
req.method("POST");
|
||||||
req.target("/");
|
req.target("/");
|
||||||
req.fields.insert("User-Agent", "test");
|
req.insert("User-Agent", "test");
|
||||||
req.body = "Hello, world!";
|
req.body = "Hello, world!";
|
||||||
prepare(req);
|
prepare(req);
|
||||||
|
|
||||||
@@ -121,8 +121,8 @@ public:
|
|||||||
relay<true>(upstream.client, downstream.server, buffer, ec,
|
relay<true>(upstream.client, downstream.server, buffer, ec,
|
||||||
[&](header<true, fields>& h, error_code& ec)
|
[&](header<true, fields>& h, error_code& ec)
|
||||||
{
|
{
|
||||||
h.fields.erase("Content-Length");
|
h.erase("Content-Length");
|
||||||
h.fields.replace("Transfer-Encoding", "chunked");
|
h.replace("Transfer-Encoding", "chunked");
|
||||||
});
|
});
|
||||||
BEAST_EXPECTS(! ec, ec.message());
|
BEAST_EXPECTS(! ec, ec.message());
|
||||||
BEAST_EXPECT(equal_body<true>(
|
BEAST_EXPECT(equal_body<true>(
|
||||||
@@ -155,7 +155,7 @@ public:
|
|||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.method(verb::get);
|
req.method(verb::get);
|
||||||
req.target("/");
|
req.target("/");
|
||||||
req.fields.insert("User-Agent", "test");
|
req.insert("User-Agent", "test");
|
||||||
error_code ec;
|
error_code ec;
|
||||||
write_ostream(os, req, ec);
|
write_ostream(os, req, ec);
|
||||||
BEAST_EXPECTS(! ec, ec.message());
|
BEAST_EXPECTS(! ec, ec.message());
|
||||||
|
@@ -99,24 +99,11 @@ public:
|
|||||||
BEAST_EXPECT(size(f) == 2);
|
BEAST_EXPECT(size(f) == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
testMethodString()
|
|
||||||
{
|
|
||||||
f_t f;
|
|
||||||
f.method_impl("CRY");
|
|
||||||
BEAST_EXPECTS(f.method_impl() == "CRY", f.method_impl());
|
|
||||||
f.method_impl("PUT");
|
|
||||||
BEAST_EXPECTS(f.method_impl() == "PUT", f.method_impl());
|
|
||||||
f.method_impl({});
|
|
||||||
BEAST_EXPECTS(f.method_impl().empty(), f.method_impl());
|
|
||||||
}
|
|
||||||
|
|
||||||
void run() override
|
void run() override
|
||||||
{
|
{
|
||||||
testHeaders();
|
testHeaders();
|
||||||
testRFC2616();
|
testRFC2616();
|
||||||
testErase();
|
testErase();
|
||||||
testMethodString();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -118,14 +118,14 @@ public:
|
|||||||
h.insert("User-Agent", "test");
|
h.insert("User-Agent", "test");
|
||||||
message<true, one_arg_body, fields> m{Arg1{}, h};
|
message<true, one_arg_body, fields> m{Arg1{}, h};
|
||||||
BEAST_EXPECT(h["User-Agent"] == "test");
|
BEAST_EXPECT(h["User-Agent"] == "test");
|
||||||
BEAST_EXPECT(m.fields["User-Agent"] == "test");
|
BEAST_EXPECT(m["User-Agent"] == "test");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
fields h;
|
fields h;
|
||||||
h.insert("User-Agent", "test");
|
h.insert("User-Agent", "test");
|
||||||
message<true, one_arg_body, fields> m{Arg1{}, std::move(h)};
|
message<true, one_arg_body, fields> m{Arg1{}, std::move(h)};
|
||||||
BEAST_EXPECT(! h.exists("User-Agent"));
|
BEAST_EXPECT(! h.exists("User-Agent"));
|
||||||
BEAST_EXPECT(m.fields["User-Agent"] == "test");
|
BEAST_EXPECT(m["User-Agent"] == "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
// swap
|
// swap
|
||||||
@@ -133,7 +133,7 @@ public:
|
|||||||
message<true, string_body, fields> m2;
|
message<true, string_body, fields> m2;
|
||||||
m1.target("u");
|
m1.target("u");
|
||||||
m1.body = "1";
|
m1.body = "1";
|
||||||
m1.fields.insert("h", "v");
|
m1.insert("h", "v");
|
||||||
m2.method("G");
|
m2.method("G");
|
||||||
m2.body = "2";
|
m2.body = "2";
|
||||||
swap(m1, m2);
|
swap(m1, m2);
|
||||||
@@ -143,8 +143,8 @@ public:
|
|||||||
BEAST_EXPECT(m2.target() == "u");
|
BEAST_EXPECT(m2.target() == "u");
|
||||||
BEAST_EXPECT(m1.body == "2");
|
BEAST_EXPECT(m1.body == "2");
|
||||||
BEAST_EXPECT(m2.body == "1");
|
BEAST_EXPECT(m2.body == "1");
|
||||||
BEAST_EXPECT(! m1.fields.exists("h"));
|
BEAST_EXPECT(! m1.exists("h"));
|
||||||
BEAST_EXPECT(m2.fields.exists("h"));
|
BEAST_EXPECT(m2.exists("h"));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MoveFields : fields
|
struct MoveFields : fields
|
||||||
@@ -187,10 +187,10 @@ public:
|
|||||||
MoveFields h;
|
MoveFields h;
|
||||||
header<true, MoveFields> r{std::move(h)};
|
header<true, MoveFields> r{std::move(h)};
|
||||||
BEAST_EXPECT(h.moved_from);
|
BEAST_EXPECT(h.moved_from);
|
||||||
BEAST_EXPECT(r.fields.moved_to);
|
BEAST_EXPECT(r.moved_to);
|
||||||
request<string_body, MoveFields> m{std::move(r)};
|
request<string_body, MoveFields> m{std::move(r)};
|
||||||
BEAST_EXPECT(r.fields.moved_from);
|
BEAST_EXPECT(r.moved_from);
|
||||||
BEAST_EXPECT(m.fields.moved_to);
|
BEAST_EXPECT(m.moved_to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,12 +202,12 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.version = 11;
|
m.version = 11;
|
||||||
m.fields.insert("Upgrade", "test");
|
m.insert("Upgrade", "test");
|
||||||
BEAST_EXPECT(! is_upgrade(m));
|
BEAST_EXPECT(! is_upgrade(m));
|
||||||
|
|
||||||
prepare(m, connection::upgrade);
|
prepare(m, connection::upgrade);
|
||||||
BEAST_EXPECT(is_upgrade(m));
|
BEAST_EXPECT(is_upgrade(m));
|
||||||
BEAST_EXPECT(m.fields["Connection"] == "upgrade");
|
BEAST_EXPECT(m["Connection"] == "upgrade");
|
||||||
|
|
||||||
m.version = 10;
|
m.version = 10;
|
||||||
BEAST_EXPECT(! is_upgrade(m));
|
BEAST_EXPECT(! is_upgrade(m));
|
||||||
@@ -220,7 +220,7 @@ public:
|
|||||||
request<string_body> m;
|
request<string_body> m;
|
||||||
m.version = 10;
|
m.version = 10;
|
||||||
BEAST_EXPECT(! is_upgrade(m));
|
BEAST_EXPECT(! is_upgrade(m));
|
||||||
m.fields.insert("Transfer-Encoding", "chunked");
|
m.insert("Transfer-Encoding", "chunked");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
prepare(m);
|
prepare(m);
|
||||||
@@ -229,8 +229,8 @@ public:
|
|||||||
catch(std::exception const&)
|
catch(std::exception const&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
m.fields.erase("Transfer-Encoding");
|
m.erase("Transfer-Encoding");
|
||||||
m.fields.insert("Content-Length", "0");
|
m.insert("Content-Length", "0");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
prepare(m);
|
prepare(m);
|
||||||
@@ -240,8 +240,8 @@ public:
|
|||||||
{
|
{
|
||||||
pass();
|
pass();
|
||||||
}
|
}
|
||||||
m.fields.erase("Content-Length");
|
m.erase("Content-Length");
|
||||||
m.fields.insert("Connection", "keep-alive");
|
m.insert("Connection", "keep-alive");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
prepare(m);
|
prepare(m);
|
||||||
@@ -252,8 +252,8 @@ public:
|
|||||||
pass();
|
pass();
|
||||||
}
|
}
|
||||||
m.version = 11;
|
m.version = 11;
|
||||||
m.fields.erase("Connection");
|
m.erase("Connection");
|
||||||
m.fields.insert("Connection", "close");
|
m.insert("Connection", "close");
|
||||||
BEAST_EXPECT(! is_keep_alive(m));
|
BEAST_EXPECT(! is_keep_alive(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +265,7 @@ public:
|
|||||||
m1.result(status::ok);
|
m1.result(status::ok);
|
||||||
m1.version = 10;
|
m1.version = 10;
|
||||||
m1.body = "1";
|
m1.body = "1";
|
||||||
m1.fields.insert("h", "v");
|
m1.insert("h", "v");
|
||||||
m2.result(status::not_found);
|
m2.result(status::not_found);
|
||||||
m2.body = "2";
|
m2.body = "2";
|
||||||
m2.version = 11;
|
m2.version = 11;
|
||||||
@@ -280,8 +280,8 @@ public:
|
|||||||
BEAST_EXPECT(m2.version == 10);
|
BEAST_EXPECT(m2.version == 10);
|
||||||
BEAST_EXPECT(m1.body == "2");
|
BEAST_EXPECT(m1.body == "2");
|
||||||
BEAST_EXPECT(m2.body == "1");
|
BEAST_EXPECT(m2.body == "1");
|
||||||
BEAST_EXPECT(! m1.fields.exists("h"));
|
BEAST_EXPECT(! m1.exists("h"));
|
||||||
BEAST_EXPECT(m2.fields.exists("h"));
|
BEAST_EXPECT(m2.exists("h"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -133,7 +133,7 @@ public:
|
|||||||
BEAST_EXPECT(m.version == 10);
|
BEAST_EXPECT(m.version == 10);
|
||||||
BEAST_EXPECT(m.result() == status::ok);
|
BEAST_EXPECT(m.result() == status::ok);
|
||||||
BEAST_EXPECT(m.reason() == "OK");
|
BEAST_EXPECT(m.reason() == "OK");
|
||||||
BEAST_EXPECT(m.fields["Server"] == "test");
|
BEAST_EXPECT(m["Server"] == "test");
|
||||||
BEAST_EXPECT(m.body == "Hello, world!");
|
BEAST_EXPECT(m.body == "Hello, world!");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -160,10 +160,10 @@ public:
|
|||||||
BEAST_EXPECT(m.version == 11);
|
BEAST_EXPECT(m.version == 11);
|
||||||
BEAST_EXPECT(m.result() == status::ok);
|
BEAST_EXPECT(m.result() == status::ok);
|
||||||
BEAST_EXPECT(m.reason() == "OK");
|
BEAST_EXPECT(m.reason() == "OK");
|
||||||
BEAST_EXPECT(m.fields["Server"] == "test");
|
BEAST_EXPECT(m["Server"] == "test");
|
||||||
BEAST_EXPECT(m.fields["Transfer-Encoding"] == "chunked");
|
BEAST_EXPECT(m["Transfer-Encoding"] == "chunked");
|
||||||
BEAST_EXPECT(m.fields["Expires"] == "never");
|
BEAST_EXPECT(m["Expires"] == "never");
|
||||||
BEAST_EXPECT(m.fields["MD5-Fingerprint"] == "-");
|
BEAST_EXPECT(m["MD5-Fingerprint"] == "-");
|
||||||
BEAST_EXPECT(m.body == "*****--");
|
BEAST_EXPECT(m.body == "*****--");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -202,7 +202,7 @@ public:
|
|||||||
[&](parser_type<true> const& p)
|
[&](parser_type<true> const& p)
|
||||||
{
|
{
|
||||||
auto const& m = p.get();
|
auto const& m = p.get();
|
||||||
BEAST_EXPECT(m.fields["X"] == "x");
|
BEAST_EXPECT(m["X"] == "x");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -226,7 +226,7 @@ public:
|
|||||||
BEAST_EXPECT(m.method() == verb::get);
|
BEAST_EXPECT(m.method() == verb::get);
|
||||||
BEAST_EXPECT(m.target() == "/");
|
BEAST_EXPECT(m.target() == "/");
|
||||||
BEAST_EXPECT(m.version == 11);
|
BEAST_EXPECT(m.version == 11);
|
||||||
BEAST_EXPECT(m.fields["User-Agent"] == "test");
|
BEAST_EXPECT(m["User-Agent"] == "test");
|
||||||
BEAST_EXPECT(m.body == "*");
|
BEAST_EXPECT(m.body == "*");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@@ -294,8 +294,8 @@ public:
|
|||||||
m.version = 10;
|
m.version = 10;
|
||||||
m.result(status::ok);
|
m.result(status::ok);
|
||||||
m.reason("OK");
|
m.reason("OK");
|
||||||
m.fields.insert("Server", "test");
|
m.insert("Server", "test");
|
||||||
m.fields.insert("Content-Length", "5");
|
m.insert("Content-Length", "5");
|
||||||
m.body = "*****";
|
m.body = "*****";
|
||||||
error_code ec;
|
error_code ec;
|
||||||
test::string_ostream ss{ios_};
|
test::string_ostream ss{ios_};
|
||||||
@@ -313,8 +313,8 @@ public:
|
|||||||
m.version = 11;
|
m.version = 11;
|
||||||
m.result(status::ok);
|
m.result(status::ok);
|
||||||
m.reason("OK");
|
m.reason("OK");
|
||||||
m.fields.insert("Server", "test");
|
m.insert("Server", "test");
|
||||||
m.fields.insert("Transfer-Encoding", "chunked");
|
m.insert("Transfer-Encoding", "chunked");
|
||||||
m.body = "*****";
|
m.body = "*****";
|
||||||
error_code ec;
|
error_code ec;
|
||||||
test::string_ostream ss(ios_);
|
test::string_ostream ss(ios_);
|
||||||
@@ -346,8 +346,8 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.version = 10;
|
m.version = 10;
|
||||||
m.fields.insert("User-Agent", "test");
|
m.insert("User-Agent", "test");
|
||||||
m.fields.insert("Content-Length", "5");
|
m.insert("Content-Length", "5");
|
||||||
m.body = "*****";
|
m.body = "*****";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -377,8 +377,8 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.version = 10;
|
m.version = 10;
|
||||||
m.fields.insert("User-Agent", "test");
|
m.insert("User-Agent", "test");
|
||||||
m.fields.insert("Transfer-Encoding", "chunked");
|
m.insert("Transfer-Encoding", "chunked");
|
||||||
m.body = "*****";
|
m.body = "*****";
|
||||||
error_code ec;
|
error_code ec;
|
||||||
write(fs, m, ec);
|
write(fs, m, ec);
|
||||||
@@ -410,8 +410,8 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.version = 10;
|
m.version = 10;
|
||||||
m.fields.insert("User-Agent", "test");
|
m.insert("User-Agent", "test");
|
||||||
m.fields.insert("Transfer-Encoding", "chunked");
|
m.insert("Transfer-Encoding", "chunked");
|
||||||
m.body = "*****";
|
m.body = "*****";
|
||||||
error_code ec;
|
error_code ec;
|
||||||
async_write(fs, m, do_yield[ec]);
|
async_write(fs, m, do_yield[ec]);
|
||||||
@@ -443,8 +443,8 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.version = 10;
|
m.version = 10;
|
||||||
m.fields.insert("User-Agent", "test");
|
m.insert("User-Agent", "test");
|
||||||
m.fields.insert("Content-Length", "5");
|
m.insert("Content-Length", "5");
|
||||||
m.body = "*****";
|
m.body = "*****";
|
||||||
error_code ec;
|
error_code ec;
|
||||||
write(fs, m, ec);
|
write(fs, m, ec);
|
||||||
@@ -471,8 +471,8 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.version = 10;
|
m.version = 10;
|
||||||
m.fields.insert("User-Agent", "test");
|
m.insert("User-Agent", "test");
|
||||||
m.fields.insert("Content-Length", "5");
|
m.insert("Content-Length", "5");
|
||||||
m.body = "*****";
|
m.body = "*****";
|
||||||
error_code ec;
|
error_code ec;
|
||||||
async_write(fs, m, do_yield[ec]);
|
async_write(fs, m, do_yield[ec]);
|
||||||
@@ -500,7 +500,7 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.version = 10;
|
m.version = 10;
|
||||||
m.fields.insert("User-Agent", "test");
|
m.insert("User-Agent", "test");
|
||||||
m.body = "*";
|
m.body = "*";
|
||||||
prepare(m);
|
prepare(m);
|
||||||
BEAST_EXPECT(str(m) ==
|
BEAST_EXPECT(str(m) ==
|
||||||
@@ -517,7 +517,7 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.version = 10;
|
m.version = 10;
|
||||||
m.fields.insert("User-Agent", "test");
|
m.insert("User-Agent", "test");
|
||||||
m.body = "*";
|
m.body = "*";
|
||||||
prepare(m, connection::keep_alive);
|
prepare(m, connection::keep_alive);
|
||||||
BEAST_EXPECT(str(m) ==
|
BEAST_EXPECT(str(m) ==
|
||||||
@@ -535,7 +535,7 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.version = 10;
|
m.version = 10;
|
||||||
m.fields.insert("User-Agent", "test");
|
m.insert("User-Agent", "test");
|
||||||
m.body = "*";
|
m.body = "*";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -553,7 +553,7 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.version = 10;
|
m.version = 10;
|
||||||
m.fields.insert("User-Agent", "test");
|
m.insert("User-Agent", "test");
|
||||||
m.body = "*";
|
m.body = "*";
|
||||||
prepare(m);
|
prepare(m);
|
||||||
test::string_ostream ss(ios_);
|
test::string_ostream ss(ios_);
|
||||||
@@ -573,7 +573,7 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.version = 11;
|
m.version = 11;
|
||||||
m.fields.insert("User-Agent", "test");
|
m.insert("User-Agent", "test");
|
||||||
m.body = "*";
|
m.body = "*";
|
||||||
prepare(m);
|
prepare(m);
|
||||||
BEAST_EXPECT(str(m) ==
|
BEAST_EXPECT(str(m) ==
|
||||||
@@ -590,7 +590,7 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.version = 11;
|
m.version = 11;
|
||||||
m.fields.insert("User-Agent", "test");
|
m.insert("User-Agent", "test");
|
||||||
m.body = "*";
|
m.body = "*";
|
||||||
prepare(m, connection::close);
|
prepare(m, connection::close);
|
||||||
test::string_ostream ss(ios_);
|
test::string_ostream ss(ios_);
|
||||||
@@ -612,7 +612,7 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.version = 11;
|
m.version = 11;
|
||||||
m.fields.insert("User-Agent", "test");
|
m.insert("User-Agent", "test");
|
||||||
prepare(m, connection::upgrade);
|
prepare(m, connection::upgrade);
|
||||||
BEAST_EXPECT(str(m) ==
|
BEAST_EXPECT(str(m) ==
|
||||||
"GET / HTTP/1.1\r\n"
|
"GET / HTTP/1.1\r\n"
|
||||||
@@ -627,7 +627,7 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.version = 11;
|
m.version = 11;
|
||||||
m.fields.insert("User-Agent", "test");
|
m.insert("User-Agent", "test");
|
||||||
m.body = "*";
|
m.body = "*";
|
||||||
prepare(m);
|
prepare(m);
|
||||||
test::string_ostream ss(ios_);
|
test::string_ostream ss(ios_);
|
||||||
@@ -652,7 +652,7 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.version = 11;
|
m.version = 11;
|
||||||
m.fields.insert("User-Agent", "test");
|
m.insert("User-Agent", "test");
|
||||||
m.body = "*";
|
m.body = "*";
|
||||||
BEAST_EXPECT(boost::lexical_cast<std::string>(m) ==
|
BEAST_EXPECT(boost::lexical_cast<std::string>(m) ==
|
||||||
"GET / HTTP/1.1\r\nUser-Agent: test\r\n\r\n*");
|
"GET / HTTP/1.1\r\nUser-Agent: test\r\n\r\n*");
|
||||||
@@ -684,7 +684,7 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.version = 11;
|
m.version = 11;
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.fields.insert("Content-Length", 5);
|
m.insert("Content-Length", 5);
|
||||||
m.body = "*****";
|
m.body = "*****";
|
||||||
async_write(os, m, handler{});
|
async_write(os, m, handler{});
|
||||||
BEAST_EXPECT(handler::count() > 0);
|
BEAST_EXPECT(handler::count() > 0);
|
||||||
@@ -706,7 +706,7 @@ public:
|
|||||||
m.method(verb::get);
|
m.method(verb::get);
|
||||||
m.version = 11;
|
m.version = 11;
|
||||||
m.target("/");
|
m.target("/");
|
||||||
m.fields.insert("Content-Length", 5);
|
m.insert("Content-Length", 5);
|
||||||
m.body = "*****";
|
m.body = "*****";
|
||||||
async_write(is, m, handler{});
|
async_write(is, m, handler{});
|
||||||
BEAST_EXPECT(handler::count() > 0);
|
BEAST_EXPECT(handler::count() > 0);
|
||||||
@@ -788,7 +788,7 @@ public:
|
|||||||
m0.version = 11;
|
m0.version = 11;
|
||||||
m0.result(status::ok);
|
m0.result(status::ok);
|
||||||
m0.reason("OK");
|
m0.reason("OK");
|
||||||
m0.fields.insert("Server", "test");
|
m0.insert("Server", "test");
|
||||||
m0.body.s = "Hello, world!\n";
|
m0.body.s = "Hello, world!\n";
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -845,7 +845,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
m0.fields.insert("Transfer-Encoding", "chunked");
|
m0.insert("Transfer-Encoding", "chunked");
|
||||||
{
|
{
|
||||||
auto m = m0;
|
auto m = m0;
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
@@ -28,11 +28,11 @@ public:
|
|||||||
req.target("/");
|
req.target("/");
|
||||||
BEAST_EXPECT(! is_upgrade(req));
|
BEAST_EXPECT(! is_upgrade(req));
|
||||||
req.method(http::verb::get);
|
req.method(http::verb::get);
|
||||||
req.fields.insert("Connection", "upgrade");
|
req.insert("Connection", "upgrade");
|
||||||
BEAST_EXPECT(! is_upgrade(req));
|
BEAST_EXPECT(! is_upgrade(req));
|
||||||
req.fields.insert("Upgrade", "websocket");
|
req.insert("Upgrade", "websocket");
|
||||||
BEAST_EXPECT(! is_upgrade(req));
|
BEAST_EXPECT(! is_upgrade(req));
|
||||||
req.fields.insert("Sec-WebSocket-Version", "13");
|
req.insert("Sec-WebSocket-Version", "13");
|
||||||
BEAST_EXPECT(is_upgrade(req));
|
BEAST_EXPECT(is_upgrade(req));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -225,7 +225,7 @@ private:
|
|||||||
d.ws.async_accept_ex(
|
d.ws.async_accept_ex(
|
||||||
[](beast::websocket::response_type& res)
|
[](beast::websocket::response_type& res)
|
||||||
{
|
{
|
||||||
res.fields.insert(
|
res.insert(
|
||||||
"Server", "async_ssl_echo_server");
|
"Server", "async_ssl_echo_server");
|
||||||
},
|
},
|
||||||
d.strand.wrap(std::move(*this)));
|
d.strand.wrap(std::move(*this)));
|
||||||
|
@@ -707,11 +707,11 @@ public:
|
|||||||
req.method(http::verb::get);
|
req.method(http::verb::get);
|
||||||
req.target("/");
|
req.target("/");
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.fields.insert("Host", "localhost");
|
req.insert("Host", "localhost");
|
||||||
req.fields.insert("Upgrade", "websocket");
|
req.insert("Upgrade", "websocket");
|
||||||
req.fields.insert("Connection", "upgrade");
|
req.insert("Connection", "upgrade");
|
||||||
req.fields.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
|
req.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
|
||||||
req.fields.insert("Sec-WebSocket-Version", "13");
|
req.insert("Sec-WebSocket-Version", "13");
|
||||||
stream<test::fail_stream<
|
stream<test::fail_stream<
|
||||||
test::string_ostream>> ws{fc, ios_};
|
test::string_ostream>> ws{fc, ios_};
|
||||||
c.accept(ws, req);
|
c.accept(ws, req);
|
||||||
@@ -721,11 +721,11 @@ public:
|
|||||||
req.method(http::verb::get);
|
req.method(http::verb::get);
|
||||||
req.target("/");
|
req.target("/");
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.fields.insert("Host", "localhost");
|
req.insert("Host", "localhost");
|
||||||
req.fields.insert("Upgrade", "websocket");
|
req.insert("Upgrade", "websocket");
|
||||||
req.fields.insert("Connection", "upgrade");
|
req.insert("Connection", "upgrade");
|
||||||
req.fields.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
|
req.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
|
||||||
req.fields.insert("Sec-WebSocket-Version", "13");
|
req.insert("Sec-WebSocket-Version", "13");
|
||||||
stream<test::fail_stream<
|
stream<test::fail_stream<
|
||||||
test::string_ostream>> ws{fc, ios_};
|
test::string_ostream>> ws{fc, ios_};
|
||||||
bool called = false;
|
bool called = false;
|
||||||
@@ -739,11 +739,11 @@ public:
|
|||||||
req.method(http::verb::get);
|
req.method(http::verb::get);
|
||||||
req.target("/");
|
req.target("/");
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.fields.insert("Host", "localhost");
|
req.insert("Host", "localhost");
|
||||||
req.fields.insert("Upgrade", "websocket");
|
req.insert("Upgrade", "websocket");
|
||||||
req.fields.insert("Connection", "upgrade");
|
req.insert("Connection", "upgrade");
|
||||||
req.fields.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
|
req.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
|
||||||
req.fields.insert("Sec-WebSocket-Version", "13");
|
req.insert("Sec-WebSocket-Version", "13");
|
||||||
stream<test::fail_stream<
|
stream<test::fail_stream<
|
||||||
test::string_ostream>> ws{fc, ios_};
|
test::string_ostream>> ws{fc, ios_};
|
||||||
c.accept(ws, req,
|
c.accept(ws, req,
|
||||||
@@ -766,11 +766,11 @@ public:
|
|||||||
req.method(http::verb::get);
|
req.method(http::verb::get);
|
||||||
req.target("/");
|
req.target("/");
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.fields.insert("Host", "localhost");
|
req.insert("Host", "localhost");
|
||||||
req.fields.insert("Upgrade", "websocket");
|
req.insert("Upgrade", "websocket");
|
||||||
req.fields.insert("Connection", "upgrade");
|
req.insert("Connection", "upgrade");
|
||||||
req.fields.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
|
req.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
|
||||||
req.fields.insert("Sec-WebSocket-Version", "13");
|
req.insert("Sec-WebSocket-Version", "13");
|
||||||
stream<test::fail_stream<
|
stream<test::fail_stream<
|
||||||
test::string_ostream>> ws{fc, ios_};
|
test::string_ostream>> ws{fc, ios_};
|
||||||
bool called = false;
|
bool called = false;
|
||||||
@@ -797,11 +797,11 @@ public:
|
|||||||
req.method(http::verb::get);
|
req.method(http::verb::get);
|
||||||
req.target("/");
|
req.target("/");
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.fields.insert("Host", "localhost");
|
req.insert("Host", "localhost");
|
||||||
req.fields.insert("Upgrade", "websocket");
|
req.insert("Upgrade", "websocket");
|
||||||
req.fields.insert("Connection", "upgrade");
|
req.insert("Connection", "upgrade");
|
||||||
req.fields.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
|
req.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
|
||||||
req.fields.insert("Sec-WebSocket-Version", "13");
|
req.insert("Sec-WebSocket-Version", "13");
|
||||||
stream<test::fail_stream<
|
stream<test::fail_stream<
|
||||||
test::string_iostream>> ws{fc, ios_,
|
test::string_iostream>> ws{fc, ios_,
|
||||||
"\x88\x82\xff\xff\xff\xff\xfc\x17"};
|
"\x88\x82\xff\xff\xff\xff\xfc\x17"};
|
||||||
@@ -825,11 +825,11 @@ public:
|
|||||||
req.method(http::verb::get);
|
req.method(http::verb::get);
|
||||||
req.target("/");
|
req.target("/");
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.fields.insert("Host", "localhost");
|
req.insert("Host", "localhost");
|
||||||
req.fields.insert("Upgrade", "websocket");
|
req.insert("Upgrade", "websocket");
|
||||||
req.fields.insert("Connection", "upgrade");
|
req.insert("Connection", "upgrade");
|
||||||
req.fields.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
|
req.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
|
||||||
req.fields.insert("Sec-WebSocket-Version", "13");
|
req.insert("Sec-WebSocket-Version", "13");
|
||||||
stream<test::fail_stream<
|
stream<test::fail_stream<
|
||||||
test::string_iostream>> ws{fc, ios_,
|
test::string_iostream>> ws{fc, ios_,
|
||||||
"xff\xff\xfc\x17"};
|
"xff\xff\xfc\x17"};
|
||||||
|
@@ -263,7 +263,7 @@ private:
|
|||||||
d.ws.async_accept_ex(
|
d.ws.async_accept_ex(
|
||||||
[](beast::websocket::response_type& res)
|
[](beast::websocket::response_type& res)
|
||||||
{
|
{
|
||||||
res.fields.insert(
|
res.insert(
|
||||||
"Server", "async_echo_server");
|
"Server", "async_echo_server");
|
||||||
},
|
},
|
||||||
std::move(*this));
|
std::move(*this));
|
||||||
|
@@ -293,7 +293,7 @@ private:
|
|||||||
ws.accept_ex(
|
ws.accept_ex(
|
||||||
[](beast::websocket::response_type& res)
|
[](beast::websocket::response_type& res)
|
||||||
{
|
{
|
||||||
res.fields.insert(
|
res.insert(
|
||||||
"Server", "sync_echo_server");
|
"Server", "sync_echo_server");
|
||||||
},
|
},
|
||||||
ec);
|
ec);
|
||||||
|
Reference in New Issue
Block a user