WebSocket handshake response is deterministic on failure:

Add test for websocket handshake failure HTTP response

fix #2364
close #2365
This commit is contained in:
Richard Hodges committed 2021-12-22 12:00:17 +01:00
1 parent 55d2ceb627
commit b5a94db2a5
4 files changed
+116 -6

No files matched your search

@@ -225,6 +225,9 @@ do_handshake(
RequestDecorator const& decorator,
error_code& ec)
{
if(res_p)
res_p->result(http::status::internal_server_error);
auto& impl = *impl_;
impl.change_status(status::handshake);
impl.reset();
@@ -275,12 +278,18 @@ do_handshake(
if(impl.check_stop_now(ec))
return;
impl.on_response(p.get(), key, ec);
if(impl.check_stop_now(ec))
return;
if(res_p)
if (res_p)
{
// If res_p is not null, move parser's response into it.
*res_p = p.release();
}
else
{
// Otherwise point res_p at the response in the parser.
res_p = &p.get();
}
impl.on_response(*res_p, key, ec);
}
//------------------------------------------------------------------------------
@@ -325,6 +334,7 @@ async_handshake(
detail::sec_ws_key_type key;
auto req = impl_->build_request(
key, host, target, &default_decorate_req);
res.result(http::status::internal_server_error);
return net::async_initiate<
HandshakeHandler,
void(error_code)>(