From f121f40277e4694a833864a6842028db8df870cc Mon Sep 17 00:00:00 2001 From: Robert Aistleitner Date: Wed, 6 Nov 2019 15:46:30 +0100 Subject: [PATCH 1/2] Fix issue with querystring list parameters According to https://github.com/mjumbewu/django-proxy/issues/15, kudos to @camdarley! --- proxy/views.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/proxy/views.py b/proxy/views.py index 97690cf..e550743 100644 --- a/proxy/views.py +++ b/proxy/views.py @@ -8,18 +8,33 @@ from urllib.parse import urlparse -def proxy_view(request, url, requests_args=None): +def querydict_to_dict(querydict): + """ + Converts a QueryDict object to a dictionary. + Unlike Django's QueryDict.dict() function, this keeps lists that + have two or more items as lists. + """ + data = {} + for key in querydict.keys(): + v = querydict.getlist(key) + if len(v) == 1: + v = v[0] + data[key] = v + return data + + +def proxy_view(request, url, requests_args=None, auth=None): """ Forward as close to an exact copy of the request as possible along to the given url. Respond with as close to an exact copy of the resulting response as possible. - If there are any additional arguments you wish to send to requests, put them in the requests_args dictionary. """ requests_args = (requests_args or {}).copy() headers = get_headers(request.META) - params = request.GET.copy() + params = QueryDict('', mutable=True) + params.update(querydict_to_dict(request.GET)) if 'headers' not in requests_args: requests_args['headers'] = {} From 70affa688990c1cf19e10f667e488609c90c0084 Mon Sep 17 00:00:00 2001 From: Robert Aistleitner Date: Wed, 6 Nov 2019 15:50:49 +0100 Subject: [PATCH 2/2] Remove unused auth argument (copy/paste issue) --- proxy/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/views.py b/proxy/views.py index e550743..8e2dc90 100644 --- a/proxy/views.py +++ b/proxy/views.py @@ -23,7 +23,7 @@ def querydict_to_dict(querydict): return data -def proxy_view(request, url, requests_args=None, auth=None): +def proxy_view(request, url, requests_args=None): """ Forward as close to an exact copy of the request as possible along to the given url. Respond with as close to an exact copy of the resulting