[Python-bugs-list] [ python-Bugs-511786 ] urllib2.py loses headers on redirect

noreply@sourceforge.net noreply@sourceforge.net
Mon, 11 Feb 2002 12:47:02 -0800


Bugs item #511786, was opened at 2002-02-01 08:56
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=511786&group_id=5470

Category: Python Library
Group: Python 2.2.1 candidate
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Greg Ward (gward)
Assigned to: Nobody/Anonymous (nobody)
Summary: urllib2.py loses headers on redirect

Initial Comment:
Using urllib2 for an HTTP request that involves a 
redirect, any custom-supplied headers are lost on the 
second (redirected) request.

Example:

>>> from urllib2 import *
>>> req = Request("http://www.python.org/doc", 
...               headers={"cookie": "foo=bar"})
>>> result = urlopen(req)

This results in two HTTP requests being sent to 
www.python.org.  The first one includes my cookie 
header:

GET /doc HTTP/1.0 
Host: www.python.org 
User-agent: Python-urllib/2.0a1 
cookie: foo=bar 

but the second one (after the fix-trailing-slash 
redirect) does not:

GET /doc/ HTTP/1.0 
Host: www.python.org 
User-agent: Python-urllib/2.0a1 

Luckily, a one-line patch (attached) seems to fix the 
bug.




----------------------------------------------------------------------

>Comment By: Greg Ward (gward)
Date: 2002-02-11 12:47

Message:
Logged In: YES 
user_id=14422

Fixed in rev 1.25 of urllib2.py.


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=511786&group_id=5470