[Python-Dev] urllib2 bug

Greg Ward gward@python.net
Fri, 1 Feb 2002 12:01:47 -0500


I've just discovered a bug in urllib2: it drops caller-supplied headers
when processing HTTP redirects.  See
  http://sourceforge.net/tracker/index.php?func=detail&aid=511786&group_id=5470&atid=105470
for details.

The fix (to HTTPRedirectHandler.http_error_302()), as near as I can
tell, is trivial:

--- Lib/urllib2.py      2001/11/09 16:46:51     1.24
+++ Lib/urllib2.py      2002/02/01 17:00:05
@@ -416,7 +416,7 @@
         # XXX Probably want to forget about the state of the current
         # request, although that might interact poorly with other
         # handlers that also use handler-specific request attributes
-        new = Request(newurl, req.get_data())
+        new = Request(newurl, req.get_data(), req.headers)
         new.error_302_dict = {}
         if hasattr(req, 'error_302_dict'):
             if len(req.error_302_dict)>10 or \

I'll check this in (2.2.1 candidate) and close the bug unless anyone
howls.

        Greg
-- 
Greg Ward - Unix bigot                                  gward@python.net
http://starship.python.net/~gward/
This message transmitted with 100% recycled electrons.