From b3c377afdb1a53998980b80de112f16130d8bec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Thu, 15 Oct 2020 00:25:35 +0200 Subject: json-rpc-test-server: WS: fix failures to upgrade Similar to ad1aba9, only here we return 426 to the client. --- json-rpc-test-server.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/json-rpc-test-server.c b/json-rpc-test-server.c index ce31b54..0cfd161 100644 --- a/json-rpc-test-server.c +++ b/json-rpc-test-server.c @@ -1003,9 +1003,10 @@ ws_handler_on_headers_complete (http_parser *parser) if (self->have_header_value) ws_handler_on_header_read (self); - // We strictly require a protocol upgrade + // We require a protocol upgrade. 1 is for "skip body", 2 is the same + // + "stop processing", return another number to indicate a problem here. if (!parser->upgrade) - return 2; + return 3; return 0; } @@ -1268,11 +1269,13 @@ ws_handler_push (struct ws_handler *self, const void *data, size_t len) ev_timer_stop (EV_DEFAULT_ &self->handshake_timeout_watcher); if (err == HPE_CB_headers_complete) + { print_debug ("WS handshake failed: %s", "missing `Upgrade' field"); - else - print_debug ("WS handshake failed: %s", - http_errno_description (err)); + FAIL_HANDSHAKE (HTTP_426_UPGRADE_REQUIRED, + "Upgrade: websocket", SEC_WS_VERSION ": 13"); + } + print_debug ("WS handshake failed: %s", http_errno_description (err)); FAIL_HANDSHAKE (HTTP_400_BAD_REQUEST); } return true; -- cgit v1.2.3