source: src/mapservice/server_impl/ValidatorWorkaround.py@ f61d16d

debian/bullseye
Last change on this file since f61d16d was ae2ff15, checked in by Joachim Langenbach <joachim.langenbach@…>, 7 years ago
  • Fixed testing environment
    • Fixed some issues in the API and it's serving
  • Property mode set to 100644
File size: 1.8 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):
22
23 def validate_response_with_request(self, request, data, status_code, headers, url):
24 if request.headers.get('accept', '') == 'application/geo+json':
25 logging.debug('Circumventing validation for application/geo+json')
26 return True
27 return self.validate_response(data, status_code, headers, url)
28
29 def __call__(self, function):
[ec9e811]30 """
31 :type function: types.FunctionType
32 :rtype: types.FunctionType
33 """
[4d83fdc]34 def _wrapper(request, response):
[ec9e811]35 connexion_response = \
36 self.operation.api.get_connexion_response(response, self.mimetype)
37 self.validate_response_with_request(
38 request,
39 connexion_response.body, connexion_response.status_code,
40 connexion_response.headers, request.url)
[4d83fdc]41
42 return response
43
[ec9e811]44 if has_coroutine(function):
45 from .coroutine_wrappers import get_response_validator_wrapper
[4d83fdc]46 wrapper = get_response_validator_wrapper(function, _wrapper)
[ec9e811]47
[4d83fdc]48 else: # pragma: 3 no cover
49 @functools.wraps(function)
50 def wrapper(request):
51 response = function(request)
52 return _wrapper(request, response)
[ec9e811]53
[4d83fdc]54 return wrapper
Note: See TracBrowser for help on using the repository browser.