[PATCH] Respect "Connection: close" headers sent by HTTP clients.
Alexis S. L. Carvalho
alexis at cecm.usp.br
Fri Jul 7 17:35:06 UTC 2006
# HG changeset patch
# User Alexis S. L. Carvalho <alexis at cecm.usp.br>
# Date 1152293631 10800
# Node ID 2bcc17a6eab049b9183e3b751e8e4680b5d367dc
# Parent 6a961a54f953e6d0f2e6760f15f42f0000e1b774
Respect "Connection: close" headers sent by HTTP clients.
A HTTP client can indicate that it doesn't support (or doesn't want)
persistent connections by sending this header.
This not only makes the server more compliant with the RFC, but also
reduces the run time of test-http-proxy when run with python 2.3 from
~125s to ~5s (it doesn't affect it with python 2.4, which was already
~5s).
diff -r 6a961a54f953 -r 2bcc17a6eab0 mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py Fri Jul 07 11:23:53 2006 +0200
+++ b/mercurial/hgweb/server.py Fri Jul 07 14:33:51 2006 -0300
@@ -127,6 +127,11 @@ class _hgwebhandler(object, BaseHTTPServ
if h[0].lower() == 'content-length':
should_close = False
self.length = int(h[1])
+ # The value of the Connection header is a list of case-insensitive
+ # tokens separated by commas and optional whitespace.
+ if 'close' in [token.strip().lower() for token in
+ self.headers.get('connection', '').split(',')]:
+ should_close = True
if should_close:
self.send_header('Connection', 'close')
self.close_connection = should_close
More information about the Mercurial
mailing list