[PATCH 4 of 4] Put support for persistent connections back in
hopper at omnifarious.org
hopper at omnifarious.org
Tue Jun 27 15:42:44 UTC 2006
# HG changeset patch
# User Eric Hopper <hopper at omnifarious.org>
# Node ID 919eb6f04840d3c01add5ccb1b6bd41566b54d8e
# Parent 11017220f60788b773d188fa432008fd7d86d1f7
Put support for persistent connections back in.
diff -r 11017220f607 -r 919eb6f04840 mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py Tue Jun 27 08:34:11 2006 -0700
+++ b/mercurial/hgweb/server.py Tue Jun 27 08:34:32 2006 -0700
@@ -109,6 +109,7 @@ class _hgwebhandler(object, BaseHTTPServ
self.saved_status = None
self.saved_headers = []
self.sent_headers = False
+ self.length = None
req = self.server.reqmaker(env, self._start_response)
for data in req:
if data:
@@ -120,8 +121,15 @@ class _hgwebhandler(object, BaseHTTPServ
saved_status = self.saved_status.split(None, 1)
saved_status[0] = int(saved_status[0])
self.send_response(*saved_status)
+ should_close = True
for h in self.saved_headers:
self.send_header(*h)
+ if h[0].lower() == 'content-length':
+ should_close = False
+ self.length = int(h[1])
+ if should_close:
+ self.send_header('Connection', 'close')
+ self.close_connection = should_close
self.end_headers()
self.sent_headers = True
@@ -129,7 +137,9 @@ class _hgwebhandler(object, BaseHTTPServ
code, msg = http_status.split(None, 1)
code = int(code)
self.saved_status = http_status
- self.saved_headers = headers
+ bad_headers = ('connection', 'transfer-encoding')
+ self.saved_headers = [ h for h in headers \
+ if h[0].lower() not in bad_headers ]
return self._write
def _write(self, data):
@@ -137,6 +147,10 @@ class _hgwebhandler(object, BaseHTTPServ
raise AssertionError("data written before start_response() called")
elif not self.sent_headers:
self.send_headers()
+ if self.length is not None:
+ if len(data) > self.length:
+ raise AssertionError("Content-length header sent, but more bytes than specified are being written.")
+ self.length = self.length - len(data)
self.wfile.write(data)
self.wfile.flush()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mercurial-scm.org/pipermail/mercurial/attachments/20060627/018242b1/attachment-0001.asc>
More information about the Mercurial
mailing list