Skip to content

Commit

Permalink
get_(wms|wfs)_url and get_wfs_url handle X-Forwarded-Proto and -Host
Browse files Browse the repository at this point in the history
  • Loading branch information
jirik committed Sep 25, 2023
1 parent 1dd5b4b commit c3e0416
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
13 changes: 8 additions & 5 deletions src/layman/layer/geoserver/util.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
6 changes: 2 additions & 4 deletions src/layman/layer/geoserver/wfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')


Expand Down
6 changes: 2 additions & 4 deletions src/layman/layer/geoserver/wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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')


Expand Down

0 comments on commit c3e0416

Please sign in to comment.