summaryrefslogtreecommitdiff
path: root/addons/hw_drivers/http.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/hw_drivers/http.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/hw_drivers/http.py')
-rw-r--r--addons/hw_drivers/http.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/addons/hw_drivers/http.py b/addons/hw_drivers/http.py
new file mode 100644
index 00000000..b0ea9bee
--- /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()