##// END OF EJS Templates
http server: support persistent connections....
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.

File last commit:

r2434:a2df85ad default
r2434:a2df85ad default
Show More
request.py
59 lines | 2.0 KiB | text/x-python | PythonLexer
Eric Hopper
Fixing up comment headers for split up code.
r2391 # hgweb/request.py - An http request from either CGI or the standalone server.
Eric Hopper
Splitting up hgweb so it's easier to change.
r2355 #
# Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net>
# Copyright 2005 Matt Mackall <mpm@selenic.com>
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
from mercurial.demandload import demandload
Benoit Boissinot
hgweb: fix errors and warnings found by pychecker...
r2394 demandload(globals(), "socket sys cgi os errno")
Eric Hopper
Splitting up hgweb so it's easier to change.
r2355 from mercurial.i18n import gettext as _
class hgrequest(object):
def __init__(self, inp=None, out=None, env=None):
self.inp = inp or sys.stdin
self.out = out or sys.stdout
self.env = env or os.environ
self.form = cgi.parse(self.inp, self.env, keep_blank_values=1)
Vadim Gelfer
http server: support persistent connections....
r2434 self.will_close = True
Eric Hopper
Splitting up hgweb so it's easier to change.
r2355
def write(self, *things):
for thing in things:
if hasattr(thing, "__iter__"):
for part in thing:
self.write(part)
else:
try:
self.out.write(str(thing))
except socket.error, inst:
if inst[0] != errno.ECONNRESET:
raise
Vadim Gelfer
http server: support persistent connections....
r2434 def done(self):
if self.will_close:
self.inp.close()
self.out.close()
else:
self.out.flush()
Eric Hopper
Splitting up hgweb so it's easier to change.
r2355 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")
Vadim Gelfer
http server: support persistent connections....
r2434 def httphdr(self, type, filename=None, length=0):
Eric Hopper
Splitting up hgweb so it's easier to change.
r2355
headers = [('Content-type', type)]
Vadim Gelfer
http server: support persistent connections....
r2434 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
Eric Hopper
Splitting up hgweb so it's easier to change.
r2355 self.header(headers)