Mercurial > public > mercurial-scm > hg-stable
diff mercurial/hgweb/request.py @ 2434:a2df85adface
http server: support persistent connections.
only "hg serve" affected yet. http server running cgi script will not
use persistent connections. support for fastcgi will help that.
clients that support keepalive can use one tcp connection for all
commands during clone and pull. this makes latency of binary search
during pull much lower over wan.
if server does not know content-length, it will force connection to
close at end. right fix is to use chunked transfer-encoding but this is
easier and does not hurt performance. only command that is affected is
"changegroup" which is always last command during a pull.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Thu, 15 Jun 2006 12:55:58 -0700 |
parents | a8f1049d1d2d |
children | 09b1c9ef317c |
line wrap: on
line diff
--- a/mercurial/hgweb/request.py Wed Jun 14 15:41:37 2006 -0700 +++ b/mercurial/hgweb/request.py Thu Jun 15 12:55:58 2006 -0700 @@ -16,6 +16,7 @@ self.out = out or sys.stdout self.env = env or os.environ self.form = cgi.parse(self.inp, self.env, keep_blank_values=1) + self.will_close = True def write(self, *things): for thing in things: @@ -29,16 +30,30 @@ if inst[0] != errno.ECONNRESET: raise + def done(self): + if self.will_close: + self.inp.close() + self.out.close() + else: + self.out.flush() + def header(self, headers=[('Content-type','text/html')]): for header in headers: self.out.write("%s: %s\r\n" % header) self.out.write("\r\n") - def httphdr(self, type, file="", size=0): + def httphdr(self, type, filename=None, length=0): headers = [('Content-type', type)] - if file: - headers.append(('Content-disposition', 'attachment; filename=%s' % file)) - if size > 0: - headers.append(('Content-length', str(size))) + if filename: + headers.append(('Content-disposition', 'attachment; filename=%s' % + filename)) + # we do not yet support http 1.1 chunked transfer, so we have + # to force connection to close if content-length not known + if length: + headers.append(('Content-length', str(length))) + self.will_close = False + else: + headers.append(('Connection', 'close')) + self.will_close = True self.header(headers)