Rev 3431: Fix bug #229076 by fixing header names before sending the request. in http://bazaar.launchpad.net/%7Evila/bzr/229076-conn-reset-by-peer
Vincent Ladeuil
v.ladeuil+lp at free.fr
Sat May 17 18:54:33 BST 2008
At http://bazaar.launchpad.net/%7Evila/bzr/229076-conn-reset-by-peer
------------------------------------------------------------
revno: 3431
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
-------------- next part --------------
=== 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-17 17:53:47 +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.items())
try:
method = request.get_method()
More information about the bazaar-commits
mailing list