djproxy icon indicating copy to clipboard operation
djproxy copied to clipboard

Handle multiple set-cookie in http response

Open FabienArcellier opened this issue 2 years ago • 0 comments

In case the server returns more than one set-cookie header, djproxy returns a single set-cookie header that is incomprehensible to the browser.

This bug is known and reported in the operation of request. It is appropriate to process this usecase to use the headers returned by urllib3 instead of the one from request.

For now, I have implemented this processing in a ForwardSetCookie middleware.

I have the impression that it should be part of the core of the library, not to be deported in a middleware. It is the role of the proxy to correctly manage headers, cookies, ... I can redo my PR if it's the case.

class ForwardSetCookie(object):
    """
    Handles the transmission of multiple cookies returned by a server as multiple set-cookie headers.

    Request merges the set-cookie headers into one. The default behavior is ok
    if the server returns only one cookie per http response.

    The browser will receive only one cookie.

    {
        Set-Cookie: hello=world; Expires=Wed, 21 Oct 2015 07:28:00 GMT, world=hello
    }

    instead

    {
        Set-Cookie: hello=world; Expires=Wed, 21 Oct 2015 07:28:00 GMT
        Set-Cookie: world=hello
    }
    pass
  • https://github.com/urllib3/urllib3/commit/d8013cb111644a06eb5cb9bccce174a1a996078d
  • https://stackoverflow.com/a/57131320
  • https://github.com/psf/requests/issues/3957#issuecomment-1047539652

FabienArcellier avatar Nov 05 '22 13:11 FabienArcellier