##// 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 import os.path
10 import os.path
11 import mimetypes
11 import mimetypes
12 from mercurial.demandload import demandload
12 from mercurial.demandload import demandload
13 demandload(globals(), "re zlib ConfigParser")
13 demandload(globals(), "re zlib ConfigParser cStringIO")
14 demandload(globals(), "mercurial:mdiff,ui,hg,util,archival,templater")
14 demandload(globals(), "mercurial:mdiff,ui,hg,util,archival,templater")
15 demandload(globals(), "mercurial.hgweb.request:hgrequest")
15 demandload(globals(), "mercurial.hgweb.request:hgrequest")
16 demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile")
16 demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile")
@@ -761,26 +761,32 b' class hgweb(object):'
761 req.form['filenode'][0]))
761 req.form['filenode'][0]))
762
762
763 elif cmd == 'heads':
763 elif cmd == 'heads':
764 req.httphdr("application/mercurial-0.1")
764 resp = " ".join(map(hex, self.repo.heads())) + "\n"
765 h = self.repo.heads()
765 req.httphdr("application/mercurial-0.1", length=len(resp))
766 req.write(" ".join(map(hex, h)) + "\n")
766 req.write(resp)
767
767
768 elif cmd == 'branches':
768 elif cmd == 'branches':
769 req.httphdr("application/mercurial-0.1")
770 nodes = []
769 nodes = []
771 if req.form.has_key('nodes'):
770 if req.form.has_key('nodes'):
772 nodes = map(bin, req.form['nodes'][0].split(" "))
771 nodes = map(bin, req.form['nodes'][0].split(" "))
772 resp = cStringIO.StringIO()
773 for b in self.repo.branches(nodes):
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 elif cmd == 'between':
779 elif cmd == 'between':
777 req.httphdr("application/mercurial-0.1")
778 nodes = []
780 nodes = []
779 if req.form.has_key('pairs'):
781 if req.form.has_key('pairs'):
780 pairs = [map(bin, p.split("-"))
782 pairs = [map(bin, p.split("-"))
781 for p in req.form['pairs'][0].split(" ")]
783 for p in req.form['pairs'][0].split(" ")]
784 resp = cStringIO.StringIO()
782 for b in self.repo.between(pairs):
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 elif cmd == 'changegroup':
791 elif cmd == 'changegroup':
786 req.httphdr("application/mercurial-0.1")
792 req.httphdr("application/mercurial-0.1")
@@ -819,3 +825,4 b' class hgweb(object):'
819
825
820 else:
826 else:
821 req.write(self.t("error"))
827 req.write(self.t("error"))
828 req.done()
@@ -16,6 +16,7 b' class hgrequest(object):'
16 self.out = out or sys.stdout
16 self.out = out or sys.stdout
17 self.env = env or os.environ
17 self.env = env or os.environ
18 self.form = cgi.parse(self.inp, self.env, keep_blank_values=1)
18 self.form = cgi.parse(self.inp, self.env, keep_blank_values=1)
19 self.will_close = True
19
20
20 def write(self, *things):
21 def write(self, *things):
21 for thing in things:
22 for thing in things:
@@ -29,16 +30,30 b' class hgrequest(object):'
29 if inst[0] != errno.ECONNRESET:
30 if inst[0] != errno.ECONNRESET:
30 raise
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 def header(self, headers=[('Content-type','text/html')]):
40 def header(self, headers=[('Content-type','text/html')]):
33 for header in headers:
41 for header in headers:
34 self.out.write("%s: %s\r\n" % header)
42 self.out.write("%s: %s\r\n" % header)
35 self.out.write("\r\n")
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 headers = [('Content-type', type)]
47 headers = [('Content-type', type)]
40 if file:
48 if filename:
41 headers.append(('Content-disposition', 'attachment; filename=%s' % file))
49 headers.append(('Content-disposition', 'attachment; filename=%s' %
42 if size > 0:
50 filename))
43 headers.append(('Content-length', str(size)))
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 self.header(headers)
59 self.header(headers)
@@ -27,6 +27,7 b' def _splitURI(uri):'
27
27
28 class _hgwebhandler(object, BaseHTTPServer.BaseHTTPRequestHandler):
28 class _hgwebhandler(object, BaseHTTPServer.BaseHTTPRequestHandler):
29 def __init__(self, *args, **kargs):
29 def __init__(self, *args, **kargs):
30 self.protocol_version = 'HTTP/1.1'
30 BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kargs)
31 BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kargs)
31
32
32 def log_error(self, format, *args):
33 def log_error(self, format, *args):
@@ -85,7 +86,7 b' class _hgwebhandler(object, BaseHTTPServ'
85
86
86 req = hgrequest(self.rfile, self.wfile, env)
87 req = hgrequest(self.rfile, self.wfile, env)
87 self.send_response(200, "Script output follows")
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 def create_server(ui, repo):
91 def create_server(ui, repo):
91 use_threads = True
92 use_threads = True
@@ -135,6 +136,7 b' def create_server(ui, repo):'
135 else:
136 else:
136 raise hg.RepoError(_('no repo found'))
137 raise hg.RepoError(_('no repo found'))
137 hgwebobj.run(req)
138 hgwebobj.run(req)
139 return req.will_close
138
140
139 class IPv6HTTPServer(MercurialHTTPServer):
141 class IPv6HTTPServer(MercurialHTTPServer):
140 address_family = getattr(socket, 'AF_INET6', None)
142 address_family = getattr(socket, 'AF_INET6', None)
General Comments 0
You need to be logged in to leave comments. Login now