From 8dfabd559d4a54f29bd04d397223da0140610c8e Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Thu, 2 Jul 2020 01:06:10 +0200 Subject: [PATCH] Respond with server_max_window_bits if applicable --- src/HttpResponse.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/HttpResponse.h b/src/HttpResponse.h index f3475fd..36ae770 100644 --- a/src/HttpResponse.h +++ b/src/HttpResponse.h @@ -224,6 +224,33 @@ public: /* Todo: remove these mid string copies */ std::string offer = extensionsNegotiator.generateOffer(); if (offer.length()) { + + /* Todo: this is a quick fix that should be properly moved to ExtensionsNegotiator */ + if (webSocketContextData->compression & DEDICATED_COMPRESSOR && + webSocketContextData->compression != DEDICATED_COMPRESSOR_256KB) { + /* 3kb, 4kb is 9, 256 is 15 (default) */ + int maxServerWindowBits = 9; + switch (webSocketContextData->compression) { + case DEDICATED_COMPRESSOR_8KB: + maxServerWindowBits = 10; + break; + case DEDICATED_COMPRESSOR_16KB: + maxServerWindowBits = 11; + break; + case DEDICATED_COMPRESSOR_32KB: + maxServerWindowBits = 12; + break; + case DEDICATED_COMPRESSOR_64KB: + maxServerWindowBits = 13; + break; + case DEDICATED_COMPRESSOR_128KB: + maxServerWindowBits = 14; + break; + } + offer += "; server_max_window_bits="; + offer += std::to_string(maxServerWindowBits); + } + writeHeader("Sec-WebSocket-Extensions", offer); }