diff --git a/src/layman/layer/geoserver/util.py b/src/layman/layer/geoserver/util.py index d779b7661..baf19a9d6 100644 --- a/src/layman/layer/geoserver/util.py +++ b/src/layman/layer/geoserver/util.py @@ -1,17 +1,20 @@ import logging from urllib.parse import urlparse - +from layman import settings +from layman.util import XForwardedClass from geoserver.util import wms_direct, wfs_direct logger = logging.getLogger(__name__) CACHE_GS_PROXY_BASE_URL_KEY = f'{__name__}:GS_PROXY_BASE_URL' DEFAULT_EXTERNAL_DB_STORE_PREFIX = 'external_db' -from layman import settings - -def get_gs_proxy_server_url(): - proxy_base_url = f'{settings.LAYMAN_PUBLIC_URL_SCHEME}://{settings.LAYMAN_PROXY_SERVER_NAME}' +def get_gs_proxy_server_url(*, x_forwarded_items=None): + x_forwarded_items = x_forwarded_items or XForwardedClass() + protocol = x_forwarded_items.proto or settings.LAYMAN_PUBLIC_URL_SCHEME + host = x_forwarded_items.host or settings.LAYMAN_PROXY_SERVER_NAME + path_prefix = x_forwarded_items.prefix or '' + proxy_base_url = f'{protocol}://{host}{path_prefix}' return proxy_base_url diff --git a/src/layman/layer/geoserver/wfs.py b/src/layman/layer/geoserver/wfs.py index 538f931af..fcacb73e1 100644 --- a/src/layman/layer/geoserver/wfs.py +++ b/src/layman/layer/geoserver/wfs.py @@ -8,7 +8,6 @@ from layman.layer.util import is_layer_chain_ready from layman import util as layman_util from layman.layer import LAYER_TYPE -from layman.util import XForwardedClass import requests_util.retry from .util import get_gs_proxy_server_url, get_external_db_store_name from . import wms @@ -60,10 +59,9 @@ def delete_layer(workspace, layername): def get_wfs_url(workspace, external_url=False, *, x_forwarded_items=None): - x_forwarded_items = x_forwarded_items or XForwardedClass() assert external_url or not x_forwarded_items - x_forwarded_prefix = x_forwarded_items.prefix or '' - base_url = urljoin(get_gs_proxy_server_url(), x_forwarded_prefix) + settings.LAYMAN_GS_PATH if external_url else settings.LAYMAN_GS_URL + base_url = get_gs_proxy_server_url(x_forwarded_items=x_forwarded_items) + settings.LAYMAN_GS_PATH \ + if external_url else settings.LAYMAN_GS_URL return urljoin(base_url, workspace + '/wfs') diff --git a/src/layman/layer/geoserver/wms.py b/src/layman/layer/geoserver/wms.py index 1657afb5d..2ddd72c7c 100644 --- a/src/layman/layer/geoserver/wms.py +++ b/src/layman/layer/geoserver/wms.py @@ -13,7 +13,6 @@ from layman.layer.util import is_layer_chain_ready from layman.layer import LAYER_TYPE from layman.layer.filesystem import gdal -from layman.util import XForwardedClass import requests_util.retry from .util import get_gs_proxy_server_url, get_external_db_store_name @@ -84,11 +83,10 @@ def delete_layer(workspace, layername): def get_wms_url(workspace, external_url=False, *, x_forwarded_items=None): - x_forwarded_items = x_forwarded_items or XForwardedClass() assert external_url or not x_forwarded_items - x_forwarded_prefix = x_forwarded_items.prefix or '' geoserver_workspace = get_geoserver_workspace(workspace) - base_url = urljoin(get_gs_proxy_server_url(), x_forwarded_prefix) + settings.LAYMAN_GS_PATH if external_url else settings.LAYMAN_GS_URL + base_url = get_gs_proxy_server_url(x_forwarded_items=x_forwarded_items) + settings.LAYMAN_GS_PATH \ + if external_url else settings.LAYMAN_GS_URL return urljoin(base_url, geoserver_workspace + '/ows')