From 780cdf1e497ea747848eb098f502b4bb078f9101 Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Fri, 27 Jan 2023 13:17:50 +0000 Subject: [PATCH] [FIX] server: avoid werkzeug >= 2.1.1 connection close Quick and dirty fix to avoid `'connection': 'close'` header with websocket. Part-of: odoo/odoo#112298 --- odoo/service/server.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/odoo/service/server.py b/odoo/service/server.py index 91506818cfe..c0d59a5acc7 100644 --- a/odoo/service/server.py +++ b/odoo/service/server.py @@ -138,6 +138,14 @@ class RequestHandler(werkzeug.serving.WSGIRequestHandler): self.protocol_version = "HTTP/1.1" return environ + def send_header(self, keyword, value): + # Prevent `WSGIRequestHandler` from sending the connection close header (compatibility with werkzeug >= 2.1.1 ) + # since it is incompatible with websocket. + if self.headers.get('Upgrade') == 'websocket' and keyword == 'Connection' and value == 'close': + # Do not keep processing requests. + self.close_connection = True + return + super().send_header(keyword, value) class ThreadedWSGIServerReloadable(LoggingBaseWSGIServerMixIn, werkzeug.serving.ThreadedWSGIServer): """ werkzeug Threaded WSGI Server patched to allow reusing a listen socket