diff options
| author | Antoine Prieels <anp@odoo.com> | 2020-10-13 12:55:09 +0000 |
|---|---|---|
| committer | Antoine Prieels <anp@odoo.com> | 2020-10-19 13:42:10 +0000 |
| commit | a6012f03ff02f04a3d128e33326f932fd22f0ced (patch) | |
| tree | 4c10dc1e6042e4862dfca91e537fdc2bf26145cc /addons/hw_drivers | |
| parent | aa287dc0f2316277d1e509b0c9033431a76d6590 (diff) | |
[IMP] hw_drivers: Remove http.py.iotpatch
We used to patch http.py using a diff. This was really not practical
because every time the file was modified, the diff had to be recreated.
We now override the specific methods directly.
closes odoo/odoo#59855
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Diffstat (limited to 'addons/hw_drivers')
| -rw-r--r-- | addons/hw_drivers/__init__.py | 1 | ||||
| -rw-r--r-- | addons/hw_drivers/http.py | 34 |
2 files changed, 35 insertions, 0 deletions
diff --git a/addons/hw_drivers/__init__.py b/addons/hw_drivers/__init__.py index b36b894717b..da5e919c051 100644 --- a/addons/hw_drivers/__init__.py +++ b/addons/hw_drivers/__init__.py @@ -6,5 +6,6 @@ from . import controllers from . import driver from . import event_manager from . import exception_logger +from . import http from . import interface from . import main diff --git a/addons/hw_drivers/http.py b/addons/hw_drivers/http.py new file mode 100644 index 00000000000..b0ea9bee700 --- /dev/null +++ b/addons/hw_drivers/http.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import http + + +class IoTBoxHttpRequest(http.HttpRequest): + def dispatch(self): + if self._is_cors_preflight(http.request.endpoint): + # Using the PoS in debug mode in v12, the call to '/hw_proxy/handshake' contains the + # 'X-Debug-Mode' header, which was removed from 'Access-Control-Allow-Headers' in v13. + # When the code of http.py is not checked out to v12 (i.e. in Community), the connection + # fails as the header is rejected and none of the devices can be used. + headers = { + 'Access-Control-Max-Age': 60 * 60 * 24, + 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, Authorization, X-Debug-Mode' + } + return http.Response(status=200, headers=headers) + return super(IoTBoxHttpRequest, self).dispatch() + + +class IoTBoxRoot(http.Root): + def setup_db(self, httprequest): + # No database on the IoT Box + pass + + def get_request(self, httprequest): + # Override HttpRequestwith IoTBoxHttpRequest + if httprequest.mimetype not in ("application/json", "application/json-rpc"): + return IoTBoxHttpRequest(httprequest) + return super(IoTBoxRoot, self).get_request(httprequest) + +http.Root = IoTBoxRoot +http.root = IoTBoxRoot() |
