equal
deleted
inserted
replaced
9 import os, cgi, sys |
9 import os, cgi, sys |
10 import mimetypes |
10 import mimetypes |
11 from demandload import demandload |
11 from demandload import demandload |
12 demandload(globals(), "mdiff time re socket zlib errno ui hg ConfigParser") |
12 demandload(globals(), "mdiff time re socket zlib errno ui hg ConfigParser") |
13 demandload(globals(), "tempfile StringIO BaseHTTPServer util SocketServer") |
13 demandload(globals(), "tempfile StringIO BaseHTTPServer util SocketServer") |
14 demandload(globals(), "archival mimetypes templater") |
14 demandload(globals(), "archival mimetypes templater urllib") |
15 from node import * |
15 from node import * |
16 from i18n import gettext as _ |
16 from i18n import gettext as _ |
|
17 |
|
18 def splitURI(uri): |
|
19 """ Return path and query splited from uri |
|
20 |
|
21 Just like CGI environment, the path is unquoted, the query is |
|
22 not. |
|
23 """ |
|
24 if '?' in uri: |
|
25 path, query = uri.split('?', 1) |
|
26 else: |
|
27 path, query = uri, '' |
|
28 return urllib.unquote(path), query |
17 |
29 |
18 def up(p): |
30 def up(p): |
19 if p[0] != "/": |
31 if p[0] != "/": |
20 p = "/" + p |
32 p = "/" + p |
21 if p[-1] == "/": |
33 if p[-1] == "/": |
916 if self.address_family is None: |
928 if self.address_family is None: |
917 raise hg.RepoError(_('IPv6 not available on this system')) |
929 raise hg.RepoError(_('IPv6 not available on this system')) |
918 BaseHTTPServer.HTTPServer.__init__(self, *args, **kwargs) |
930 BaseHTTPServer.HTTPServer.__init__(self, *args, **kwargs) |
919 |
931 |
920 class hgwebhandler(BaseHTTPServer.BaseHTTPRequestHandler): |
932 class hgwebhandler(BaseHTTPServer.BaseHTTPRequestHandler): |
|
933 |
921 def log_error(self, format, *args): |
934 def log_error(self, format, *args): |
922 errorlog.write("%s - - [%s] %s\n" % (self.address_string(), |
935 errorlog.write("%s - - [%s] %s\n" % (self.address_string(), |
923 self.log_date_time_string(), |
936 self.log_date_time_string(), |
924 format % args)) |
937 format % args)) |
925 |
938 |
937 |
950 |
938 def do_GET(self): |
951 def do_GET(self): |
939 self.do_POST() |
952 self.do_POST() |
940 |
953 |
941 def do_hgweb(self): |
954 def do_hgweb(self): |
942 query = "" |
955 path_info, query = splitURI(self.path) |
943 p = self.path.find("?") |
956 |
944 if p: |
|
945 query = self.path[p + 1:] |
|
946 query = query.replace('+', ' ') |
|
947 |
|
948 env = {} |
957 env = {} |
949 env['GATEWAY_INTERFACE'] = 'CGI/1.1' |
958 env['GATEWAY_INTERFACE'] = 'CGI/1.1' |
950 env['REQUEST_METHOD'] = self.command |
959 env['REQUEST_METHOD'] = self.command |
951 env['SERVER_NAME'] = self.server.server_name |
960 env['SERVER_NAME'] = self.server.server_name |
952 env['SERVER_PORT'] = str(self.server.server_port) |
961 env['SERVER_PORT'] = str(self.server.server_port) |
953 env['REQUEST_URI'] = "/" |
962 env['REQUEST_URI'] = "/" |
|
963 env['PATH_INFO'] = path_info |
954 if query: |
964 if query: |
955 env['QUERY_STRING'] = query |
965 env['QUERY_STRING'] = query |
956 host = self.address_string() |
966 host = self.address_string() |
957 if host != self.client_address[0]: |
967 if host != self.client_address[0]: |
958 env['REMOTE_HOST'] = host |
968 env['REMOTE_HOST'] = host |
975 |
985 |
976 req = hgrequest(self.rfile, self.wfile, env) |
986 req = hgrequest(self.rfile, self.wfile, env) |
977 self.send_response(200, "Script output follows") |
987 self.send_response(200, "Script output follows") |
978 |
988 |
979 if webdir_conf: |
989 if webdir_conf: |
980 hgwebobj = hgwebdir(hgwebdir_conf) |
990 hgwebobj = hgwebdir(webdir_conf) |
981 else: |
991 else: |
982 hgwebobj = hgweb(repo.__class__(repo.ui, repo.origroot)) |
992 hgwebobj = hgweb(repo.__class__(repo.ui, repo.origroot)) |
983 hgwebobj.run(req) |
993 hgwebobj.run(req) |
984 |
994 |
985 |
995 |