##// END OF EJS Templates
http server: support persistent connections....
Vadim Gelfer -
r2434:a2df85ad default
parent child Browse files
Show More
@@ -10,7 +10,7 b' import os'
10 10 import os.path
11 11 import mimetypes
12 12 from mercurial.demandload import demandload
13 demandload(globals(), "re zlib ConfigParser")
13 demandload(globals(), "re zlib ConfigParser cStringIO")
14 14 demandload(globals(), "mercurial:mdiff,ui,hg,util,archival,templater")
15 15 demandload(globals(), "mercurial.hgweb.request:hgrequest")
16 16 demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile")
@@ -761,26 +761,32 b' class hgweb(object):'
761 761 req.form['filenode'][0]))
762 762
763 763 elif cmd == 'heads':
764 req.httphdr("application/mercurial-0.1")
765 h = self.repo.heads()
766 req.write(" ".join(map(hex, h)) + "\n")
764 resp = " ".join(map(hex, self.repo.heads())) + "\n"
765 req.httphdr("application/mercurial-0.1", length=len(resp))
766 req.write(resp)
767 767
768 768 elif cmd == 'branches':
769 req.httphdr("application/mercurial-0.1")
770 769 nodes = []
771 770 if req.form.has_key('nodes'):
772 771 nodes = map(bin, req.form['nodes'][0].split(" "))
772 resp = cStringIO.StringIO()
773 773 for b in self.repo.branches(nodes):
774 req.write(" ".join(map(hex, b)) + "\n")
774 resp.write(" ".join(map(hex, b)) + "\n")
775 resp = resp.getvalue()
776 req.httphdr("application/mercurial-0.1", length=len(resp))
777 req.write(resp)
775 778
776 779 elif cmd == 'between':
777 req.httphdr("application/mercurial-0.1")
778 780 nodes = []
779 781 if req.form.has_key('pairs'):
780 782 pairs = [map(bin, p.split("-"))
781 783 for p in req.form['pairs'][0].split(" ")]
784 resp = cStringIO.StringIO()
782 785 for b in self.repo.between(pairs):
783 req.write(" ".join(map(hex, b)) + "\n")
786 resp.write(" ".join(map(hex, b)) + "\n")
787 resp = resp.getvalue()
788 req.httphdr("application/mercurial-0.1", length=len(resp))
789 req.write(resp)
784 790
785 791 elif cmd == 'changegroup':
786 792 req.httphdr("application/mercurial-0.1")
@@ -819,3 +825,4 b' class hgweb(object):'
819 825
820 826 else:
821 827 req.write(self.t("error"))
828 req.done()
@@ -16,6 +16,7 b' class hgrequest(object):'
16 16 self.out = out or sys.stdout
17 17 self.env = env or os.environ
18 18 self.form = cgi.parse(self.inp, self.env, keep_blank_values=1)
19 self.will_close = True
19 20
20 21 def write(self, *things):
21 22 for thing in things:
@@ -29,16 +30,30 b' class hgrequest(object):'
29 30 if inst[0] != errno.ECONNRESET:
30 31 raise
31 32
33 def done(self):
34 if self.will_close:
35 self.inp.close()
36 self.out.close()
37 else:
38 self.out.flush()
39
32 40 def header(self, headers=[('Content-type','text/html')]):
33 41 for header in headers:
34 42 self.out.write("%s: %s\r\n" % header)
35 43 self.out.write("\r\n")
36 44
37 def httphdr(self, type, file="", size=0):
45 def httphdr(self, type, filename=None, length=0):
38 46
39 47 headers = [('Content-type', type)]
40 if file:
41 headers.append(('Content-disposition', 'attachment; filename=%s' % file))
42 if size > 0:
43 headers.append(('Content-length', str(size)))
48 if filename:
49 headers.append(('Content-disposition', 'attachment; filename=%s' %
50 filename))
51 # we do not yet support http 1.1 chunked transfer, so we have
52 # to force connection to close if content-length not known
53 if length:
54 headers.append(('Content-length', str(length)))
55 self.will_close = False
56 else:
57 headers.append(('Connection', 'close'))
58 self.will_close = True
44 59 self.header(headers)
@@ -27,6 +27,7 b' def _splitURI(uri):'
27 27
28 28 class _hgwebhandler(object, BaseHTTPServer.BaseHTTPRequestHandler):
29 29 def __init__(self, *args, **kargs):
30 self.protocol_version = 'HTTP/1.1'
30 31 BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kargs)
31 32
32 33 def log_error(self, format, *args):
@@ -85,7 +86,7 b' class _hgwebhandler(object, BaseHTTPServ'
85 86
86 87 req = hgrequest(self.rfile, self.wfile, env)
87 88 self.send_response(200, "Script output follows")
88 self.server.make_and_run_handler(req)
89 self.close_connection = self.server.make_and_run_handler(req)
89 90
90 91 def create_server(ui, repo):
91 92 use_threads = True
@@ -135,6 +136,7 b' def create_server(ui, repo):'
135 136 else:
136 137 raise hg.RepoError(_('no repo found'))
137 138 hgwebobj.run(req)
139 return req.will_close
138 140
139 141 class IPv6HTTPServer(MercurialHTTPServer):
140 142 address_family = getattr(socket, 'AF_INET6', None)
General Comments 0
You need to be logged in to leave comments. Login now