update
This commit is contained in:
parent
59a148076b
commit
8923642a72
23
odoo/http.py
23
odoo/http.py
@ -136,6 +136,7 @@ import functools
|
||||
import glob
|
||||
import hashlib
|
||||
import hmac
|
||||
import importlib.metadata
|
||||
import inspect
|
||||
import json
|
||||
import logging
|
||||
@ -145,7 +146,6 @@ import re
|
||||
import threading
|
||||
import time
|
||||
import traceback
|
||||
import warnings
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import datetime, timedelta
|
||||
from hashlib import sha512
|
||||
@ -278,7 +278,7 @@ ROUTING_KEYS = {
|
||||
'alias', 'host', 'methods',
|
||||
}
|
||||
|
||||
if parse_version(werkzeug.__version__) >= parse_version('2.0.2'):
|
||||
if parse_version(importlib.metadata.version('werkzeug')) >= parse_version('2.0.2'):
|
||||
# Werkzeug 2.0.2 adds the websocket option. If a websocket request
|
||||
# (ws/wss) is trying to access an HTTP route, a WebsocketMismatch
|
||||
# exception is raised. On the other hand, Werkzeug 0.16 does not
|
||||
@ -711,7 +711,7 @@ def route(route=None, **routing):
|
||||
# Sanitize the routing
|
||||
assert routing.get('type', 'http') in _dispatchers.keys()
|
||||
if route:
|
||||
routing['routes'] = route if isinstance(route, list) else [route]
|
||||
routing['routes'] = [route] if isinstance(route, str) else route
|
||||
wrong = routing.pop('method', None)
|
||||
if wrong is not None:
|
||||
_logger.warning("%s defined with invalid routing parameter 'method', assuming 'methods'", fname)
|
||||
@ -1278,6 +1278,7 @@ class HTTPRequest:
|
||||
httprequest.user_agent_class = UserAgent # use vendored userAgent since it will be removed in 2.1
|
||||
httprequest.parameter_storage_class = werkzeug.datastructures.ImmutableOrderedMultiDict
|
||||
httprequest.max_content_length = DEFAULT_MAX_CONTENT_LENGTH
|
||||
httprequest.max_form_memory_size = 10 * 1024 * 1024 # 10 MB
|
||||
|
||||
self.__wrapped = httprequest
|
||||
self.__environ = self.__wrapped.environ
|
||||
@ -1739,7 +1740,7 @@ class Request:
|
||||
if isinstance(location, URL):
|
||||
location = location.to_url()
|
||||
if local:
|
||||
location = '/' + url_parse(location).replace(scheme='', netloc='').to_url().lstrip('/')
|
||||
location = '/' + url_parse(location).replace(scheme='', netloc='').to_url().lstrip('/\\')
|
||||
if self.db:
|
||||
return self.env['ir.http']._redirect(location, code)
|
||||
return werkzeug.utils.redirect(location, code, Response=Response)
|
||||
@ -1831,8 +1832,12 @@ class Request:
|
||||
try:
|
||||
directory = root.statics[module]
|
||||
filepath = werkzeug.security.safe_join(directory, path)
|
||||
debug = (
|
||||
'assets' in self.session.debug and
|
||||
' wkhtmltopdf ' not in self.httprequest.user_agent.string
|
||||
)
|
||||
res = Stream.from_path(filepath, public=True).get_response(
|
||||
max_age=0 if 'assets' in self.session.debug else STATIC_CACHE,
|
||||
max_age=0 if debug else STATIC_CACHE,
|
||||
content_security_policy=None,
|
||||
)
|
||||
root.set_csp(res)
|
||||
@ -1963,6 +1968,7 @@ class Request:
|
||||
raise # bubble up to odoo.http.Application.__call__
|
||||
if 'werkzeug' in config['dev_mode'] and self.dispatcher.routing_type != 'json':
|
||||
raise # bubble up to werkzeug.debug.DebuggedApplication
|
||||
if not hasattr(exc, 'error_response'):
|
||||
exc.error_response = self.registry['ir.http']._handle_error(exc)
|
||||
raise
|
||||
|
||||
@ -2204,7 +2210,7 @@ class JsonRPCDispatcher(Dispatcher):
|
||||
response = {'jsonrpc': '2.0', 'id': self.request_id}
|
||||
if error is not None:
|
||||
response['error'] = error
|
||||
if result is not None:
|
||||
else:
|
||||
response['result'] = result
|
||||
|
||||
return self.request.make_json_response(response)
|
||||
@ -2271,7 +2277,7 @@ class Application:
|
||||
for url, endpoint in _generate_routing_rules([''] + odoo.conf.server_wide_modules, nodb_only=True):
|
||||
routing = submap(endpoint.routing, ROUTING_KEYS)
|
||||
if routing['methods'] is not None and 'OPTIONS' not in routing['methods']:
|
||||
routing['methods'] = routing['methods'] + ['OPTIONS']
|
||||
routing['methods'] = [*routing['methods'], 'OPTIONS']
|
||||
rule = werkzeug.routing.Rule(url, endpoint=endpoint, **routing)
|
||||
rule.merge_slashes = False
|
||||
nodb_routing_map.add(rule)
|
||||
@ -2360,8 +2366,7 @@ class Application:
|
||||
|
||||
if self.get_static_file(httprequest.path):
|
||||
response = request._serve_static()
|
||||
elif request.db or httprequest.path.startswith('/preview-url/'):
|
||||
request.db = httprequest.args.get('db', request.db).split('?')[0] if httprequest.args.get('db') else request.db
|
||||
elif request.db:
|
||||
try:
|
||||
with request._get_profiler_context_manager():
|
||||
response = request._serve_db()
|
||||
|
Loading…
Reference in New Issue
Block a user