source: src/mapservice/server_impl/ValidatorWorkaround.py@ 7be94aa

debian/bullseye
Last change on this file since 7be94aa was 7be94aa, checked in by Joachim Langenbach <joachim.langenbach@…>, 7 years ago
  • Added yapf style config (src/python-style.yapf)
    • Updated all files to the yapf formatted version
  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[4d83fdc]1"""Hacks needed to circumvent connexion validation
2
3There is a bug on the connexion library concerning content negotiation and
4response validation. See https://github.com/zalando/connexion/issues/860 and
5https://github.com/zalando/connexion/pull/760
6
7Until this issue is fixed, we need to find a way to avoid a false validation
8error when a requests sends an 'application/geo+json' accept header
9"""
10import functools
11import logging
12
13from connexion.decorators.response import ResponseValidator
14from connexion import problem
15from connexion.exceptions import NonConformingResponseBody, NonConformingResponseHeaders
16from connexion.utils import has_coroutine
17
18logger = logging.getLogger(__name__)
19
20
21class ValidatorWorkaround(ResponseValidator):
[7be94aa]22 def validate_response_with_request(
23 self, request, data, status_code, headers, url
24 ):
25 if request.headers.get('accept', '') == 'application/geo+json':
26 logging.debug('Circumventing validation for application/geo+json')
27 return True
28 return self.validate_response(data, status_code, headers, url)
29
30 def __call__(self, function):
31 """
[ec9e811]32 :type function: types.FunctionType
33 :rtype: types.FunctionType
34 """
[7be94aa]35 def _wrapper(request, response):
36 connexion_response = \
37 self.operation.api.get_connexion_response(response, self.mimetype)
38 self.validate_response_with_request(
39 request, connexion_response.body,
40 connexion_response.status_code, connexion_response.headers,
41 request.url
42 )
43
44 return response
45
46 if has_coroutine(function):
47 from .coroutine_wrappers import get_response_validator_wrapper
48 wrapper = get_response_validator_wrapper(function, _wrapper)
49
50 else: # pragma: 3 no cover
51
52 @functools.wraps(function)
53 def wrapper(request):
54 response = function(request)
55 return _wrapper(request, response)
56
57 return wrapper
Note: See TracBrowser for help on using the repository browser.