forked from boostorg/beast
New HTTP interfaces (API Change):
fix #123 fix #154 fix #265 This completely replaces the HTTP parser used to read and parse incoming messages. The new version is faster than the old one, and written in fewer lines. A summary of changes: * parse and async_parse renamed to read and async_read * basic_parser is optimized for linear buffers, use flat_streambuf for the best performance with these functions: - http::read - http::read_some - http::async_read - http::async_read_some * The overloads of read() and async_read() which take just a header have been removed, since they would throw away important parse metadata. * The derived class callbacks for basic_parser have been streamlined. All strings passed to callbacks are presented in their entirety, instead of being provided in pieces. These changes allow use-cases that were previously difficult or impossible, such as: - Efficient relaying - Late body type commitment - Expect: 100-continue handling
This commit is contained in:
1 parent
34830a1780
commit
e8be3fd7d3
74 files changed
+7106
-5972
No files matched your search
@@ -83,17 +83,18 @@ reset()
|
||||
}
|
||||
|
||||
template<class NextLayer>
|
||||
http::request<http::empty_body>
|
||||
http::request_header
|
||||
stream<NextLayer>::
|
||||
build_request(boost::string_ref const& host,
|
||||
boost::string_ref const& resource, std::string& key)
|
||||
{
|
||||
http::request<http::empty_body> req;
|
||||
http::request_header req;
|
||||
req.url = { resource.data(), resource.size() };
|
||||
req.version = 11;
|
||||
req.method = "GET";
|
||||
req.fields.insert("Host", host);
|
||||
req.fields.insert("Upgrade", "websocket");
|
||||
req.fields.insert("Connection", "upgrade");
|
||||
key = detail::make_sec_ws_key(maskgen_);
|
||||
req.fields.insert("Sec-WebSocket-Key", key);
|
||||
req.fields.insert("Sec-WebSocket-Version", "13");
|
||||
@@ -113,15 +114,13 @@ build_request(boost::string_ref const& host,
|
||||
req.fields, config);
|
||||
}
|
||||
d_(req);
|
||||
http::prepare(req, http::connection::upgrade);
|
||||
return req;
|
||||
}
|
||||
|
||||
template<class NextLayer>
|
||||
template<class Body, class Fields>
|
||||
http::response<http::string_body>
|
||||
http::response_header
|
||||
stream<NextLayer>::
|
||||
build_response(http::request<Body, Fields> const& req)
|
||||
build_response(http::request_header const& req)
|
||||
{
|
||||
auto err =
|
||||
[&](std::string const& text)
|
||||
@@ -170,7 +169,7 @@ build_response(http::request<Body, Fields> const& req)
|
||||
return res;
|
||||
}
|
||||
}
|
||||
http::response<http::string_body> res;
|
||||
http::response_header res;
|
||||
{
|
||||
detail::pmd_offer offer;
|
||||
detail::pmd_offer unused;
|
||||
@@ -182,23 +181,22 @@ build_response(http::request<Body, Fields> const& req)
|
||||
res.reason = http::reason_string(res.status);
|
||||
res.version = req.version;
|
||||
res.fields.insert("Upgrade", "websocket");
|
||||
res.fields.insert("Connection", "upgrade");
|
||||
{
|
||||
auto const key =
|
||||
req.fields["Sec-WebSocket-Key"];
|
||||
res.fields.insert("Sec-WebSocket-Accept",
|
||||
detail::make_sec_ws_accept(key));
|
||||
}
|
||||
res.fields.replace("Server", "Beast.WSProto");
|
||||
res.fields.replace("Server", "Beast.WebSocket");
|
||||
d_(res);
|
||||
http::prepare(res, http::connection::upgrade);
|
||||
return res;
|
||||
}
|
||||
|
||||
template<class NextLayer>
|
||||
template<class Body, class Fields>
|
||||
void
|
||||
stream<NextLayer>::
|
||||
do_response(http::response<Body, Fields> const& res,
|
||||
do_response(http::response_header const& res,
|
||||
boost::string_ref const& key, error_code& ec)
|
||||
{
|
||||
// VFALCO Review these error codes
|
||||
|
||||
Reference in new issue
Block a user