Mercurial > hg
changeset 2508:ab460a3f0e3a
Put support for persistent connections back in.
author | Eric Hopper <hopper@omnifarious.org> |
---|---|
date | Tue, 27 Jun 2006 00:09:37 -0700 |
parents | 7e01da2bc7f3 |
children | 6350b01d173f |
files | mercurial/hgweb/server.py |
diffstat | 1 files changed, 15 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/server.py Tue Jun 27 00:09:35 2006 -0700 +++ b/mercurial/hgweb/server.py Tue Jun 27 00:09:37 2006 -0700 @@ -109,6 +109,7 @@ 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 @@ 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 @@ 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 @@ 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()