diff --git a/.coverage.8674b3a12c0a.9.XzQXStzx b/.coverage.8674b3a12c0a.9.XzQXStzx new file mode 100644 index 0000000000..820c9db8ab Binary files /dev/null and b/.coverage.8674b3a12c0a.9.XzQXStzx differ diff --git a/Makefile b/Makefile index f4c088c1b8..1a15bac4fe 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ DEV_CREATE_OEREBLEX_TABLES_SCRIPT = $(VENV_BIN)/create_oereblex_tables MODEL_PK_TYPE_IS_STRING ?= true -PRINT_URL ?= http://oereb-print:8080/print/oereb +PRINT_URL ?= http://svamaa-print-1:8080/print/oereb # ******************** # Variable definitions diff --git a/dev/config/create_yaml.py b/dev/config/create_yaml.py index d53911c5f7..ac54837021 100644 --- a/dev/config/create_yaml.py +++ b/dev/config/create_yaml.py @@ -8,7 +8,7 @@ def _create_yaml_config_( name='pyramid_oereb.yml', database='postgresql://postgres:password@localhost/pyramid_oereb', - print_url='http://oereb-print:8080/print/oereb'): + print_url='http://svamaa-print-1:8080/print/oereb'): """ Creates the specified YAML file using a template. This YAML file contains the standard configuration to run a oereb server out of the box. @@ -61,7 +61,7 @@ def create_yaml(): dest='print_url', metavar='PRINT_URL', type='string', - default='http://oereb-print:8080/print/oereb', + default='http://svamaa-print-1:8080/print/oereb', help='The URL of the print server' ) options, args = parser.parse_args() diff --git a/development.ini.mako b/development.ini.mako index 1d8133082f..ae366a6792 100644 --- a/development.ini.mako +++ b/development.ini.mako @@ -14,6 +14,16 @@ pyramid.default_locale_name = en pyramid_oereb.cfg.file = %(here)s/pyramid_oereb.yml pyramid_oereb.cfg.section = pyramid_oereb +# Enable debug toolbar +pyramid.includes = pyramid_debugtoolbar +debugtoolbar.hosts = 0.0.0.0/0 +debugtoolbar.enabled = true +debugtoolbar.intercept_exc = display +debugtoolbar.max_request_history = 100 +debugtoolbar.panels = headers logging performance renderings + request_vars sqlalchemy traceback + + sqlalchemy.url = sqlite:///%(here)s/pyramid_oereb.sqlite ### diff --git a/pyproject.toml b/pyproject.toml index db124ffb37..54daca6350 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,7 +52,8 @@ recommend = [ "requests==2.32.3", "geolink-formatter==2.0.5", "pyconizer==0.1.4", - "c2cwsgiutils[standard]==6.0.8"] + "c2cwsgiutils[standard]==6.0.8", + "Brotli==1.1.0"] no-version = [ "pypdf", "filetype", diff --git a/pyramid_oereb/core/views/webservice.py b/pyramid_oereb/core/views/webservice.py index f60e3381a0..2c40fb3143 100644 --- a/pyramid_oereb/core/views/webservice.py +++ b/pyramid_oereb/core/views/webservice.py @@ -4,6 +4,8 @@ # import yappi import qrcode import io +import brotli +import gzip # import re from pyramid.httpexceptions import HTTPBadRequest, HTTPSeeOther, HTTPInternalServerError, HTTPNoContent, \ @@ -74,7 +76,7 @@ def get_versions(self): if output_format == 'json': response.content_type = 'application/json; charset=UTF-8' response.extras = OerebStats(service='GetVersions', output_format=output_format) - return response + return self.__response_compression__(self, response) def get_capabilities(self): """ @@ -115,7 +117,7 @@ def get_capabilities(self): if output_format == 'json': response.content_type = 'application/json; charset=UTF-8' response.extras = OerebStats(service='GetCapabilities', output_format=output_format) - return response + return self.__response_compression__(self, response) def get_egrid(self): """ @@ -168,7 +170,7 @@ def get_egrid(self): params=dict(self._params), output_format=output_format ) - return response + return self.__response_compression__(self, response) def _get_egrid_coord(self, params): """ @@ -342,7 +344,8 @@ def get_extract_by_id(self): response.extras = OerebStats(service='GetExtractById', params={'error': response.message}) except AttributeError: response.extras = OerebStats(service='GetExtractById') - return response + + return self.__response_compression__(self, response) def __validate_extract_params__(self): """ @@ -523,7 +526,8 @@ def __get_egrid_response__(self, records, params): ) response.extras = OerebStats(service='GetEGRID', output_format=output_format) - return response + + return self.__response_compression__(self, response) @staticmethod def __parse_en__(en, buffer_dist=None): @@ -607,6 +611,33 @@ def __redirect_to_dynamic_client__(real_estate): raise HTTPInternalServerError('Missing configuration for redirect to dynamic client.') return HTTPSeeOther(url.format(**vars(real_estate))) + @staticmethod + def __response_compression__(self, response): + """ + Returns a response object where the body is compressed using brotli or gzip, + depending on the accepted encoding. + + Args: + response (pyramid.response.Response): + the generated 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)) + + return response class Parameter(object): def __init__(self, response_format, with_geometry=False, images=False, signed=False, identdn=None,