eshad / httplib2

Automatically exported from code.google.com/p/httplib2
0 stars 0 forks source link

cookie not set on 302 redirect #153

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Setup a server page which both sets cookie and return 302 code
2. Connect to this page using httplib2

What is the expected output? What do you see instead?

The 302 page should set cookie, but it doesn't.

What version of the product are you using? On what operating system?
httplib2 0.6.0, Linux.

Please provide any additional information below.

Original issue reported on code.google.com by cyker...@gmail.com on 17 Jun 2011 at 3:50

GoogleCodeExporter commented 9 years ago
A correction of formulation. When I set follow_redirects = False, I find after 
visiting the 302 page, the cookie is set. So I guess when follow_redirects is 
set to True, this cookie is auto discarded when visiting the page to redirect 
to (i.e. the Location page). However, this might not be what the user wants, 
because the cookies set by the 302 page may be useful in the Location page.

Original comment by cyker...@gmail.com on 17 Jun 2011 at 4:18

GoogleCodeExporter commented 9 years ago
httplib2 has no cookie handling yet.

Original comment by joe.gregorio@gmail.com on 17 Jun 2011 at 5:39

GoogleCodeExporter commented 9 years ago
Hi Joe,

I also have this problem, and have a simple work-around by adding one line 
coding.

In httplib2.Http._request(), there is a part of redirection handling. So, I add 
my code as below.

                    if response.has_key('location'):
                        location = response['location']
                        old_response = copy.deepcopy(response)
                        if not old_response.has_key('content-location'):
                            old_response['content-location'] = absolute_uri
                        redirect_method = method
                        if response.status in [302, 303]:
                            # Add by Deren
                            headers['Cookie'] = response['set-cookie']
                            redirect_method = "GET"
                            body = None
                        (response, content) = self.request(location, redirect_method, body=body, headers = headers, redirections = redirections - 1)
                        response.previous = old_response

Just for your reference!

Good luck,
Deren

Original comment by dere...@gmail.com on 5 Nov 2013 at 8:02