django-proxy icon indicating copy to clipboard operation
django-proxy copied to clipboard

List parameters in get request are not correctly transmitted

Open camdarley opened this issue 5 years ago • 3 comments

Hi, When a GET request with list list parameters, such as http://<hostname>?selected=A&selected=B, is proxied to an endpoint, only last parameter "B" is transmitted (using request.GET.getList('selected') ) Regards

camdarley avatar Jul 09 '19 15:07 camdarley

I managed to make it working by using this piece of code:

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 = QueryDict('', mutable=True)
    params.update(querydict_to_dict(request.GET))

    if 'headers' not in requests_args:
        requests_args['headers'] = {}
...

camdarley avatar Jul 09 '19 16:07 camdarley

+1 on this

jimcasteleiro avatar Dec 13 '19 14:12 jimcasteleiro

+1 On the issue. I've used the workaround @camdarley recommended and uninstalled the library.

sabriozgur avatar Nov 02 '20 13:11 sabriozgur