Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List parameters in get request are not correctly transmitted #15

Open
camdarley opened this issue Jul 9, 2019 · 3 comments
Open

List parameters in get request are not correctly transmitted #15

camdarley opened this issue Jul 9, 2019 · 3 comments

Comments

@camdarley
Copy link

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
Copy link
Author

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'] = {}
...

robertaistleitner pushed a commit to robertaistleitner/django-proxy that referenced this issue Nov 6, 2019
@jimcasteleiro
Copy link

+1 on this

@sabriozgur
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants