Merge lp:~vila/bzr/2.2-568421-http-error-length into lp:bzr/2.2

Proposed by Vincent Ladeuil
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 5062
Proposed branch: lp:~vila/bzr/2.2-568421-http-error-length
Merge into: lp:bzr/2.2
Diff against target: 58 lines (+38/-0)
2 files modified
NEWS (+3/-0)
bzrlib/tests/http_server.py (+35/-0)
To merge this branch: bzr merge lp:~vila/bzr/2.2-568421-http-error-length
Reviewer Review Type Date Requested Status
John A Meinel Needs Fixing
Review via email: mp+30423@code.launchpad.net

Commit message

Set a Content-Length header on errors for HTTP/1.1

Description of the change

Targeting 2.2 since this concerns maverick and using the right basis this time.

This fixes bug #568421 which was only occurring on gentoo when pycurl was used with gnutls
so far (which made it harder to reproduce, at least for me).

This is due to a long standing bug in the python BaseHTTPServer: some http/1.1 clients requires a length even if the connection is closed. pycurl/gnutls seems to be the only combination choking on this one (but pycurl is also pretty pedantic about connection closes).

It looks like maverick changed the ssl implementation used for pycurl (which made the bug easier to reproduce) so the diagnosis was easier.

There is no easy way to reuse the base send_error so I went for a simplified implementation less likely to fail in the future.

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vincent Ladeuil wrote:
> Vincent Ladeuil has proposed merging lp:~vila/bzr/2.2-568421-http-error-length into lp:bzr/2.2.
>
> Requested reviews:
> bzr-core (bzr-core)
> Related bugs:
> #568421 test_get_unknown_file fails for pycurl if curl was compiled against gnutls
> https://bugs.launchpad.net/bugs/568421
>
>
> Targeting 2.2 since this concerns maverick and using the right basis this time.
>
> This fixes bug #568421 which was only occurring on gentoo when pycurl was used with gnutls
> so far (which made it harder to reproduce, at least for me).
>
> This is due to a long standing bug in the python BaseHTTPServer: some http/1.1 clients requires a length even if the connection is closed. pycurl/gnutls seems to be the only combination choking on this one (but pycurl is also pretty pedantic about connection closes).
>
> It looks like maverick changed the ssl implementation used for pycurl (which made the bug easier to reproduce) so the diagnosis was easier.
>
> There is no easy way to reuse the base send_error so I went for a simplified implementation less likely to fail in the future.
>

Consider my comments on the bzr.dev proposal to apply here.

 review: needsfixing

(fine to land on 2.2, as long as we don't send content-length
inappropriately, and the class attributes are put somewhere discoverable.)

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkxFwBYACgkQJdeBCYSNAAP+ZwCgr3MtoaWbABdeHHpKqJNi2gbi
8mYAoMOrHt209ZoozBWnjxMjrO3yLXjd
=0X6m
-----END PGP SIGNATURE-----

review: Needs Fixing
Revision history for this message
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2010-07-19 10:44:20 +0000
+++ NEWS 2010-07-20 15:21:19 +0000
@@ -38,6 +38,9 @@
38* Don't traceback trying to unversion children files of an already38* Don't traceback trying to unversion children files of an already
39 unversioned directory. (Vincent Ladeuil, #494221)39 unversioned directory. (Vincent Ladeuil, #494221)
4040
41* ``HTTP/1.1` test servers now set a ``Content-Length`` header to comply
42 with pedantic ``HTTP/1.1`` clients. (Vincent Ladeuil, #568421)
43
41* Progress bars prefer to truncate the text message rather than the44* Progress bars prefer to truncate the text message rather than the
42 counters. The spinner is shown between the network transfer indicator45 counters. The spinner is shown between the network transfer indicator
43 and the progress message. (Martin Pool)46 and the progress message. (Martin Pool)
4447
=== modified file 'bzrlib/tests/http_server.py'
--- bzrlib/tests/http_server.py 2010-02-23 07:43:11 +0000
+++ bzrlib/tests/http_server.py 2010-07-20 15:21:19 +0000
@@ -89,6 +89,41 @@
89 errno.ECONNABORTED, errno.EBADF)):89 errno.ECONNABORTED, errno.EBADF)):
90 raise90 raise
9191
92 error_content_type = 'text/plain'
93 error_message_format = '''\
94Error code: %(code)s.
95Message: %(message)s.
96'''
97
98 def send_error(self, code, message=None):
99 """Send and log an error reply.
100
101 We redefine the python-provided version to be able to set a
102 ``Content-Length`` header as some http/1.1 clients complain otherwise
103 (see bug #568421).
104
105 :param code: The HTTP error code.
106
107 :param message: The explanation of the error code, Defaults to a short
108 entry.
109 """
110
111 if message is None:
112 try:
113 message = self.responses[code][0]
114 except KeyError:
115 message = '???'
116 self.log_error("code %d, message %s", code, message)
117 content = (self.error_message_format %
118 {'code': code, 'message': message})
119 self.send_response(code, message)
120 self.send_header("Content-Type", self.error_content_type)
121 self.send_header("Content-Length", "%d" % len(content))
122 self.send_header('Connection', 'close')
123 self.end_headers()
124 if self.command != 'HEAD' and code >= 200 and code not in (204, 304):
125 self.wfile.write(content)
126
92 _range_regexp = re.compile(r'^(?P<start>\d+)-(?P<end>\d+)$')127 _range_regexp = re.compile(r'^(?P<start>\d+)-(?P<end>\d+)$')
93 _tail_regexp = re.compile(r'^-(?P<tail>\d+)$')128 _tail_regexp = re.compile(r'^-(?P<tail>\d+)$')
94129

Subscribers

People subscribed via source and target branches