Include full path when determining proxy host url

Session validation includes a method for determining the proxy host url,
but previously did not include the path for the initial request. This
caused a situation where users with a new session would not be able to
complete their first search, since the session validation follow-through
url did not include the actual path for their search query.

The method now includes a flag for only extracting the root url, which
is needed for creating full urls in the content filter.

Fixes #708
This commit is contained in:
Ben Busby 2022-08-02 10:55:45 -06:00
parent aa198ed562
commit 2eee0b87d5
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1
2 changed files with 7 additions and 4 deletions

View File

@ -35,11 +35,11 @@ def get_request_url(url: str) -> str:
return url
def get_proxy_host_url(r: Request, default: str) -> str:
scheme = r.headers.get('X-Forwarded-Proto', 'http')
def get_proxy_host_url(r: Request, default: str, root=False) -> str:
scheme = r.headers.get('X-Forwarded-Proto', 'https')
http_host = r.headers.get('X-Forwarded-Host')
if http_host:
return f'{scheme}://{http_host}/'
return f'{scheme}://{http_host}{r.full_path if not root else "/"}'
return default

View File

@ -117,7 +117,10 @@ class Search:
"""
mobile = 'Android' in self.user_agent or 'iPhone' in self.user_agent
# reconstruct url if X-Forwarded-Host header present
root_url = get_proxy_host_url(self.request, self.request.url_root)
root_url = get_proxy_host_url(
self.request,
self.request.url_root,
root=True)
content_filter = Filter(self.session_key,
root_url=root_url,