From beb0c25a94ec81c340f16e7c77a7a3d44a0c0f89 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 29 Sep 2023 09:43:11 +0200 Subject: [PATCH] [IMP] core, bus: future werkzeug compatibility fixes - `Response.charset` is deprecated since 2.3, `Response.set_cookie` accesses the currently-extent internal `_charset` directly until this too gets removed in Werkzeug 3.0. Add a `_charset` to `FutureResponse` so this does not crash. - Bytes response headers are deprecated since 2.3, and will get removed in 3.0, passing bytes in websocket is completely unnecessary happenstance which is trivially fixed. closes odoo/odoo#137145 X-original-commit: 66e3040d4ad9e03aabefebd4799f699ad30fca45 Signed-off-by: Julien Castiaux (juc) Signed-off-by: Xavier Morel (xmo) --- addons/bus/websocket.py | 2 +- odoo/http.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/bus/websocket.py b/addons/bus/websocket.py index 91b628f4a96..21ddc3de770 100644 --- a/addons/bus/websocket.py +++ b/addons/bus/websocket.py @@ -862,7 +862,7 @@ class WebsocketConnectionHandler: return Response(status=101, headers={ 'Upgrade': 'websocket', 'Connection': 'Upgrade', - 'Sec-WebSocket-Accept': accept_header, + 'Sec-WebSocket-Accept': accept_header.decode(), }) @classmethod diff --git a/odoo/http.py b/odoo/http.py index a1a27076257..2d6afc1b927 100644 --- a/odoo/http.py +++ b/odoo/http.py @@ -1274,6 +1274,10 @@ class FutureResponse: def __init__(self): self.headers = werkzeug.datastructures.Headers() + @property + def _charset(self): + return self.charset + @functools.wraps(werkzeug.Response.set_cookie) def set_cookie(self, key, value='', max_age=None, expires=-1, path='/', domain=None, secure=False, httponly=False, samesite=None, cookie_type='required'): if expires == -1: # not forced value -> default value -> 1 year