Skip to content

Commit

Permalink
fix linting & check headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Anne Maier committed Aug 28, 2024
1 parent 4b1e76e commit 2990618
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions pyramid_oereb/core/views/webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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))

Check warning on line 640 in pyramid_oereb/core/views/webservice.py

View check run for this annotation

Codecov / codecov/patch

pyramid_oereb/core/views/webservice.py#L629-L640

Added lines #L629 - L640 were not covered by tests

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):
Expand Down

0 comments on commit 2990618

Please sign in to comment.