From 29906182faab0f5e9809d7accd096496dc814a5c Mon Sep 17 00:00:00 2001 From: Anne Maier Date: Wed, 28 Aug 2024 07:44:43 +0200 Subject: [PATCH] fix linting & check headers --- pyramid_oereb/core/views/webservice.py | 31 ++++++++++++++------------ 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/pyramid_oereb/core/views/webservice.py b/pyramid_oereb/core/views/webservice.py index 2c40fb3143..2d610d9a7f 100644 --- a/pyramid_oereb/core/views/webservice.py +++ b/pyramid_oereb/core/views/webservice.py @@ -344,7 +344,7 @@ def get_extract_by_id(self): response.extras = OerebStats(service='GetExtractById', params={'error': response.message}) except AttributeError: response.extras = OerebStats(service='GetExtractById') - + return self.__response_compression__(self, response) def __validate_extract_params__(self): @@ -624,21 +624,24 @@ def __response_compression__(self, response): Returns: pyramid.response.Response: The response. """ - if 'br' in self._request.headers['ACCEPT_ENCODING']: - response.content_encoding = 'br' - compressed_response = brotli.compress(response.body) - response.content_length = str(len(compressed_response)) - response.body = compressed_response - elif 'gzip' in self._request.headers['ACCEPT_ENCODING']: - response.content_encoding = 'gzip' - gzip_buffer = io.BytesIO() - with gzip.GzipFile(mode='wb', fileobj=gzip_buffer) as gzip_file: - gzip_file.write(response.body) - response.body = gzip_buffer.getvalue() - response.content_length = str(len(response.body)) - + + if 'ACCEPT_ENCODING' in self._request.headers: + if 'br' in self._request.headers['ACCEPT_ENCODING']: + response.content_encoding = 'br' + compressed_response = brotli.compress(response.body) + response.content_length = str(len(compressed_response)) + response.body = compressed_response + elif 'gzip' in self._request.headers['ACCEPT_ENCODING']: + response.content_encoding = 'gzip' + gzip_buffer = io.BytesIO() + with gzip.GzipFile(mode='wb', fileobj=gzip_buffer) as gzip_file: + gzip_file.write(response.body) + response.body = gzip_buffer.getvalue() + response.content_length = str(len(response.body)) + return response + class Parameter(object): def __init__(self, response_format, with_geometry=False, images=False, signed=False, identdn=None, number=None, egrid=None, language=None, topics=None, extract_url=None, qr_code_ref=None):