Commit ead7877d authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis
Browse files

snf-django-lib: AssertionError in proxy

When we use proxy, we have to check that path starts with
the given proxy_base, and raise an AssertionError otherwise.

The check was there but it was wrong (there was missing
a not) and also no exception was raised.
parent 1ee5a9dd
......@@ -68,9 +68,9 @@ def proxy(request, proxy_base=None, target_base=None):
# set X-Forwarded-For, if already set, pass it through, otherwise set it
# to the current request remote address
SOURCE_IP = request.META.get('REMOTE_ADDR', None)
if SOURCE_IP and not 'X-Forwarded-For' in headers:
headers['X-Forwarded-For'] = SOURCE_IP
source_ip = request.META.get('REMOTE_ADDR', None)
if source_ip and not 'X-Forwarded-For' in headers:
headers['X-Forwarded-For'] = source_ip
# request.META remains cleanup
for k in headers.keys():
......@@ -84,9 +84,10 @@ def proxy(request, proxy_base=None, target_base=None):
kwargs['body'] = request.raw_post_data
path = request.path.lstrip('/')
if path.startswith(proxy_base):
if not path.startswith(proxy_base):
m = "request path '{0}' does not start with proxy_base '{1}'"
m = m.format(path, proxy_base)
raise AssertionError(m)
path = path.replace(proxy_base, '', 1)
path = join_urls(target_base, path)
with PooledHTTPConnection(parsed.netloc, parsed.scheme) as conn:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment