From e3c98a03cca563e3ce968e4eb198d532df25ebaf Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Thu, 27 May 2021 10:54:10 -0700 Subject: [PATCH] (websocket server) Handle and accept firefox browser special upgrade value (keep-alive, Upgrade) --- docs/CHANGELOG.md | 4 ++++ ixwebsocket/IXHttp.cpp | 2 +- ixwebsocket/IXNetSystem.cpp | 2 +- ixwebsocket/IXWebSocketHandshake.cpp | 6 +++++- ixwebsocket/IXWebSocketVersion.h | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 18d24c2f..7ef2feaf 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,10 @@ All changes to this project will be documented in this file. +## [11.2.7] - 2021-05-27 + +(websocket server) Handle and accept firefox browser special upgrade value (keep-alive, Upgrade) + ## [11.2.6] - 2021-05-18 (Windows) move EINVAL (re)definition from IXSocket.h to IXNetSystem.h (fix #289) diff --git a/ixwebsocket/IXHttp.cpp b/ixwebsocket/IXHttp.cpp index 46212cf2..56a466c0 100644 --- a/ixwebsocket/IXHttp.cpp +++ b/ixwebsocket/IXHttp.cpp @@ -137,7 +137,7 @@ namespace ix { contentLength = std::stoi(headers["Content-Length"]); } - catch(const std::exception&) + catch (const std::exception&) { return std::make_tuple( false, "Error parsing HTTP Header 'Content-Length'", httpRequest); diff --git a/ixwebsocket/IXNetSystem.cpp b/ixwebsocket/IXNetSystem.cpp index c6510510..c4b71aeb 100644 --- a/ixwebsocket/IXNetSystem.cpp +++ b/ixwebsocket/IXNetSystem.cpp @@ -192,7 +192,7 @@ namespace ix return ::inet_ntop(af, a0, s, l); #endif } - + #if defined(_WIN32) && defined(__GNUC__) static int hexval(unsigned c) { diff --git a/ixwebsocket/IXWebSocketHandshake.cpp b/ixwebsocket/IXWebSocketHandshake.cpp index 8b2735da..9a8de059 100644 --- a/ixwebsocket/IXWebSocketHandshake.cpp +++ b/ixwebsocket/IXWebSocketHandshake.cpp @@ -204,6 +204,9 @@ namespace ix // Check the value of the connection field // Some websocket servers (Go/Gorilla?) send lowercase values for the // connection header, so do a case insensitive comparison + // + // See https://github.com/apache/thrift/commit/7c4bdf9914fcba6c89e0f69ae48b9675578f084a + // if (!insensitiveStringCompare(headers["connection"], "Upgrade")) { std::stringstream ss; @@ -296,7 +299,8 @@ namespace ix return sendErrorResponse(400, "Missing Upgrade header"); } - if (!insensitiveStringCompare(headers["upgrade"], "WebSocket")) + if (!insensitiveStringCompare(headers["upgrade"], "WebSocket") && + headers["Upgrade"] != "keep-alive, Upgrade") // special case for firefox { return sendErrorResponse(400, "Invalid Upgrade header, " diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index e6e2b37c..af1743e3 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "11.2.6" +#define IX_WEBSOCKET_VERSION "11.2.7"