Skip to content

Commit

Permalink
Always resolve attachment URL to an absolute URL relative to the feat…
Browse files Browse the repository at this point in the history
…ureinfo request origin
  • Loading branch information
manisandro committed Dec 9, 2024
1 parent 683e074 commit 631c6b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/feature_info_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(self, tenant, logger):
self.default_wms_url = config.get(
'default_qgis_server_url', 'http://localhost:8001/ows/')
self.data_service_url = config.get(
'data_service_url', '/api/v1/data/').rstrip('/') + '/'
'data_service_url', '/api/v1/data/').rstrip('/')
self.transform_image_urls = config.get('transform_image_urls', True)
self.skip_empty_attributes = config.get('skip_empty_attributes', False)
self.use_permission_attribute_order = config.get('use_permission_attribute_order', False)
Expand All @@ -121,10 +121,11 @@ def __init__(self, tenant, logger):

self.db_engine = DatabaseEngine()

def query(self, identity, service_name, layers, params):
def query(self, identity, origin, service_name, layers, params):
"""Query layers and return info result as XML.
:param str identity: User identity
:param str origin: Request origin
:param str service_name: Service name
:param list(str): List of query layer names
:param obj params: FeatureInfo service params
Expand Down Expand Up @@ -167,7 +168,7 @@ def query(self, identity, service_name, layers, params):
layer_infos = []
for layer_style in expanded_layers:
info = self.get_layer_info(
identity, service_name, layer_style['layer'], layer_style['style'], x, y, crs, dict(params)
identity, origin, service_name, layer_style['layer'], layer_style['style'], x, y, crs, dict(params)
)
if info is not None:
layer_infos.append(info)
Expand Down Expand Up @@ -228,10 +229,11 @@ def expand_group_layers(self, requested_layers, requested_styles, group_layers,

return expanded_layers

def get_layer_info(self, identity, service_name, layer, style, x, y, crs, params):
def get_layer_info(self, identity, origin, service_name, layer, style, x, y, crs, params):
"""Get info for a layer rendered as info template.
:param str identity: User identity
:param str origin: Request origin
:param str service_name: Service name
:param str layer: Layer name
:param str style: Style name
Expand Down Expand Up @@ -426,6 +428,8 @@ def get_layer_info(self, identity, service_name, layer, style, x, y, crs, params
value = self.parse_value(attr.get('value'), json_aliases)
if isinstance(value, str) and value.startswith("attachment://"):
value = self.data_service_url + "/" + service_name + "." + layer + "/attachment?file=" + value[13:]
if not value.startswith('http'):
value = origin + value
alias = attribute_aliases.get(name, name)
info_feature.add(name, value, alias, json_aliases)

Expand Down
7 changes: 6 additions & 1 deletion src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,14 @@ def __process_request(self, args, service_name):
else:
api.abort(404, "Either filter, filter_geom, or i and j, are required")

origin = request.origin
headers = request.headers
if not origin and headers.get("Host") and headers.get("X-Forwarded-Proto"):
origin = headers.get("X-Forwarded-Proto") + "://" + headers.get("Host")

info_service = info_service_handler()
result = info_service.query(
get_identity_or_auth(info_service), service_name, layers, params
get_identity_or_auth(info_service), origin, service_name, layers, params
)

return Response(
Expand Down

0 comments on commit 631c6b4

Please sign in to comment.