Rev 3431: (vila) Force header names case to work-around buggy servers/proxies in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Sun May 18 11:41:41 BST 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3431
revision-id:pqm at pqm.ubuntu.com-20080518104127-7dezgqfdvymf4xvu
parent: pqm at pqm.ubuntu.com-20080517004133-6476aqcg9uf8zn0c
parent: v.ladeuil+lp at free.fr-20080518081710-afd2ag3gwkkud70d
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sun 2008-05-18 11:41:27 +0100
message:
  (vila) Force header names case to work-around buggy servers/proxies
  	(#229076)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
    ------------------------------------------------------------
    revno: 3430.1.1
    revision-id:v.ladeuil+lp at free.fr-20080518081710-afd2ag3gwkkud70d
    parent: pqm at pqm.ubuntu.com-20080517004133-6476aqcg9uf8zn0c
    parent: v.ladeuil+lp at free.fr-20080518081426-t425yejtha3bd1ow
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: trunk
    timestamp: Sun 2008-05-18 10:17:10 +0200
    message:
      (vila) Force header names case to work-around buggy servers/proxies (#229076)
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
    ------------------------------------------------------------
    revno: 3430.2.3
    revision-id:v.ladeuil+lp at free.fr-20080518081426-t425yejtha3bd1ow
    parent: v.ladeuil+lp at free.fr-20080518073422-iy08xdty0komg39e
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 229076-conn-reset-by-peer
    timestamp: Sun 2008-05-18 10:14:26 +0200
    message:
      (vila) Fix #229076
    ------------------------------------------------------------
    revno: 3430.2.2
    revision-id:v.ladeuil+lp at free.fr-20080518073422-iy08xdty0komg39e
    parent: v.ladeuil+lp at free.fr-20080517175347-our2rugcwl67zgv5
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 229076-conn-reset-by-peer
    timestamp: Sun 2008-05-18 09:34:22 +0200
    message:
      Fixed as per Matt Nordhoff review.
      
      * bzrlib/transport/http/_urllib2_wrappers.py:
      (AbstractHTTPHandler.do_open): Use iteritems instead of items to
      avoid a useless copy.
    modified:
      bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
    ------------------------------------------------------------
    revno: 3430.2.1
    revision-id:v.ladeuil+lp at free.fr-20080517175347-our2rugcwl67zgv5
    parent: pqm at pqm.ubuntu.com-20080517004133-6476aqcg9uf8zn0c
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 229076-conn-reset-by-peer
    timestamp: Sat 2008-05-17 19:53:47 +0200
    message:
      Fix bug #229076 by fixing header names before sending the request.
      
      * bzrlib/transport/http/_urllib2_wrappers.py:
      (AbstractHTTPHandler.do_open): Title header names before sending
      the request or some exotic servers or proxies may choke.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
=== modified file 'NEWS'
--- a/NEWS	2008-05-17 00:41:33 +0000
+++ b/NEWS	2008-05-17 17:53:47 +0000
@@ -31,6 +31,9 @@
       used for an ssh scheme (sftp or bzr+ssh).
       (Vincent Ladeuil, #203186)
 
+    * Properly *title* header names in http requests instead of capitalizing
+      them.
+      (Vincent Ladeuil, #229076)
 
   DOCUMENTATION:
 

=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
--- a/bzrlib/transport/http/_urllib2_wrappers.py	2008-04-24 07:22:53 +0000
+++ b/bzrlib/transport/http/_urllib2_wrappers.py	2008-05-18 07:34:22 +0000
@@ -30,6 +30,10 @@
 
 And a custom Request class that lets us track redirections, and
 handle authentication schemes.
+
+For coherency with python libraries, we use capitalized header names throughout
+the code, even if the header names will be titled just before sending the
+request (see AbstractHTTPHandler.do_open).
 """
 
 DEBUG = 0
@@ -407,10 +411,6 @@
     _default_headers = {'Pragma': 'no-cache',
                         'Cache-control': 'max-age=0',
                         'Connection': 'Keep-Alive',
-                        # FIXME: Spell it User-*A*gent once we
-                        # know how to properly avoid bogus
-                        # urllib2 using capitalize() for headers
-                        # instead of title(sp?).
                         'User-agent': 'bzr/%s (urllib)' % bzrlib_version,
                         'Accept': '*/*',
                         }
@@ -511,6 +511,13 @@
         headers = {}
         headers.update(request.header_items())
         headers.update(request.unredirected_hdrs)
+        # Some servers or proxies will choke on headers not properly
+        # cased. httplib/urllib/urllib2 all use capitalize to get canonical
+        # header names, but only python2.5 urllib2 use title() to fix them just
+        # before sending the request. And not all versions of python 2.5 do
+        # that. Since we replace urllib2.AbstractHTTPHandler.do_open we do it
+        # ourself below.
+        headers = dict((name.title(), val) for name, val in headers.iteritems())
 
         try:
             method = request.get_method()




More information about the bazaar-commits mailing list