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
1=== modified file 'NEWS'
2--- NEWS 2010-07-19 10:44:20 +0000
3+++ NEWS 2010-07-20 15:21:19 +0000
4@@ -38,6 +38,9 @@
5 * Don't traceback trying to unversion children files of an already
6 unversioned directory. (Vincent Ladeuil, #494221)
7
8+* ``HTTP/1.1` test servers now set a ``Content-Length`` header to comply
9+ with pedantic ``HTTP/1.1`` clients. (Vincent Ladeuil, #568421)
10+
11 * Progress bars prefer to truncate the text message rather than the
12 counters. The spinner is shown between the network transfer indicator
13 and the progress message. (Martin Pool)
14
15=== modified file 'bzrlib/tests/http_server.py'
16--- bzrlib/tests/http_server.py 2010-02-23 07:43:11 +0000
17+++ bzrlib/tests/http_server.py 2010-07-20 15:21:19 +0000
18@@ -89,6 +89,41 @@
19 errno.ECONNABORTED, errno.EBADF)):
20 raise
21
22+ error_content_type = 'text/plain'
23+ error_message_format = '''\
24+Error code: %(code)s.
25+Message: %(message)s.
26+'''
27+
28+ def send_error(self, code, message=None):
29+ """Send and log an error reply.
30+
31+ We redefine the python-provided version to be able to set a
32+ ``Content-Length`` header as some http/1.1 clients complain otherwise
33+ (see bug #568421).
34+
35+ :param code: The HTTP error code.
36+
37+ :param message: The explanation of the error code, Defaults to a short
38+ entry.
39+ """
40+
41+ if message is None:
42+ try:
43+ message = self.responses[code][0]
44+ except KeyError:
45+ message = '???'
46+ self.log_error("code %d, message %s", code, message)
47+ content = (self.error_message_format %
48+ {'code': code, 'message': message})
49+ self.send_response(code, message)
50+ self.send_header("Content-Type", self.error_content_type)
51+ self.send_header("Content-Length", "%d" % len(content))
52+ self.send_header('Connection', 'close')
53+ self.end_headers()
54+ if self.command != 'HEAD' and code >= 200 and code not in (204, 304):
55+ self.wfile.write(content)
56+
57 _range_regexp = re.compile(r'^(?P<start>\d+)-(?P<end>\d+)$')
58 _tail_regexp = re.compile(r'^-(?P<tail>\d+)$')
59

Subscribers

People subscribed via source and target branches