Show More
@@ -0,0 +1,74 b'' | |||||
|
1 | #!/bin/sh | |||
|
2 | ||||
|
3 | mkdir repo | |||
|
4 | cd repo | |||
|
5 | hg init | |||
|
6 | echo foo > bar | |||
|
7 | hg add bar | |||
|
8 | hg commit -m "test" -d "0 0" -u "Testing" | |||
|
9 | hg tip | |||
|
10 | ||||
|
11 | cat > request.py <<EOF | |||
|
12 | from mercurial.hgweb import hgweb, hgwebdir | |||
|
13 | from StringIO import StringIO | |||
|
14 | import os, sys | |||
|
15 | ||||
|
16 | errors = StringIO() | |||
|
17 | input = StringIO() | |||
|
18 | ||||
|
19 | def startrsp(headers, data): | |||
|
20 | print '---- HEADERS' | |||
|
21 | print headers | |||
|
22 | print '---- DATA' | |||
|
23 | print data | |||
|
24 | return output.write | |||
|
25 | ||||
|
26 | env = { | |||
|
27 | 'wsgi.version': (1, 0), | |||
|
28 | 'wsgi.url_scheme': 'http', | |||
|
29 | 'wsgi.errors': errors, | |||
|
30 | 'wsgi.input': input, | |||
|
31 | 'wsgi.multithread': False, | |||
|
32 | 'wsgi.multiprocess': False, | |||
|
33 | 'wsgi.run_once': False, | |||
|
34 | 'REQUEST_METHOD': 'GET', | |||
|
35 | 'SCRIPT_NAME': '', | |||
|
36 | 'SERVER_NAME': '127.0.0.1', | |||
|
37 | 'SERVER_PORT': os.environ['HGPORT'], | |||
|
38 | 'SERVER_PROTOCOL': 'HTTP/1.0' | |||
|
39 | } | |||
|
40 | ||||
|
41 | output = StringIO() | |||
|
42 | env['PATH_INFO'] = '/' | |||
|
43 | env['QUERY_STRING'] = 'style=atom' | |||
|
44 | hgweb('.', name = 'repo')(env, startrsp) | |||
|
45 | print output.getvalue() | |||
|
46 | print '---- ERRORS' | |||
|
47 | print errors.getvalue() | |||
|
48 | ||||
|
49 | output = StringIO() | |||
|
50 | env['PATH_INFO'] = '/file/tip/' | |||
|
51 | env['QUERY_STRING'] = 'style=raw' | |||
|
52 | hgweb('.', name = 'repo')(env, startrsp) | |||
|
53 | print output.getvalue() | |||
|
54 | print '---- ERRORS' | |||
|
55 | print errors.getvalue() | |||
|
56 | ||||
|
57 | output = StringIO() | |||
|
58 | env['PATH_INFO'] = '/' | |||
|
59 | env['QUERY_STRING'] = 'style=raw' | |||
|
60 | hgwebdir({'repo': '.'})(env, startrsp) | |||
|
61 | print output.getvalue() | |||
|
62 | print '---- ERRORS' | |||
|
63 | print errors.getvalue() | |||
|
64 | ||||
|
65 | output = StringIO() | |||
|
66 | env['PATH_INFO'] = '/repo/file/tip/' | |||
|
67 | env['QUERY_STRING'] = 'style=raw' | |||
|
68 | hgwebdir({'repo': '.'})(env, startrsp) | |||
|
69 | print output.getvalue() | |||
|
70 | print '---- ERRORS' | |||
|
71 | print errors.getvalue() | |||
|
72 | EOF | |||
|
73 | ||||
|
74 | python request.py | sed "s/http:\/\/127\.0\.0\.1:[0-9]*\//http:\/\/127.0.0.1\//" |
@@ -0,0 +1,72 b'' | |||||
|
1 | changeset: 0:4cbec7e6f8c4 | |||
|
2 | tag: tip | |||
|
3 | user: Testing | |||
|
4 | date: Thu Jan 01 00:00:00 1970 +0000 | |||
|
5 | summary: test | |||
|
6 | ||||
|
7 | ---- HEADERS | |||
|
8 | 200 Script output follows | |||
|
9 | ---- DATA | |||
|
10 | [('content-type', 'application/atom+xml; charset=ascii')] | |||
|
11 | <?xml version="1.0" encoding="ascii"?> | |||
|
12 | <feed xmlns="http://www.w3.org/2005/Atom"> | |||
|
13 | <!-- Changelog --> | |||
|
14 | <id>http://127.0.0.1/</id> | |||
|
15 | <link rel="self" href="http://127.0.0.1/atom-log"/> | |||
|
16 | <link rel="alternate" href="http://127.0.0.1/"/> | |||
|
17 | <title>repo Changelog</title> | |||
|
18 | <updated>1970-01-01T00:00:00+00:00</updated> | |||
|
19 | ||||
|
20 | <entry> | |||
|
21 | <title>test</title> | |||
|
22 | <id>http://www.selenic.com/mercurial/#changeset-4cbec7e6f8c42eb52b6b52670e1f7560ae9a101e</id> | |||
|
23 | <link href="http://127.0.0.1/rev/4cbec7e6f8c42eb52b6b52670e1f7560ae9a101e"/> | |||
|
24 | <author> | |||
|
25 | <name>Testing</name> | |||
|
26 | <email>Testing</email> | |||
|
27 | </author> | |||
|
28 | <updated>1970-01-01T00:00:00+00:00</updated> | |||
|
29 | <published>1970-01-01T00:00:00+00:00</published> | |||
|
30 | <content type="xhtml"> | |||
|
31 | <div xmlns="http://www.w3.org/1999/xhtml"> | |||
|
32 | <pre xml:space="preserve">test</pre> | |||
|
33 | </div> | |||
|
34 | </content> | |||
|
35 | </entry> | |||
|
36 | ||||
|
37 | </feed> | |||
|
38 | ||||
|
39 | ---- ERRORS | |||
|
40 | ||||
|
41 | ---- HEADERS | |||
|
42 | 200 Script output follows | |||
|
43 | ---- DATA | |||
|
44 | [('content-type', 'text/plain; charset=ascii')] | |||
|
45 | ||||
|
46 | -rw-r--r-- 4 bar | |||
|
47 | ||||
|
48 | ||||
|
49 | ||||
|
50 | ---- ERRORS | |||
|
51 | ||||
|
52 | ---- HEADERS | |||
|
53 | 200 Script output follows | |||
|
54 | ---- DATA | |||
|
55 | [('content-type', 'text/plain; charset=ascii')] | |||
|
56 | ||||
|
57 | /repo/ | |||
|
58 | ||||
|
59 | ||||
|
60 | ---- ERRORS | |||
|
61 | ||||
|
62 | ---- HEADERS | |||
|
63 | 200 Script output follows | |||
|
64 | ---- DATA | |||
|
65 | [('content-type', 'text/plain; charset=ascii')] | |||
|
66 | ||||
|
67 | -rw-r--r-- 4 bar | |||
|
68 | ||||
|
69 | ||||
|
70 | ||||
|
71 | ---- ERRORS | |||
|
72 |
@@ -726,37 +726,21 b' class hgweb(object):' | |||||
726 | def rewrite_request(req): |
|
726 | def rewrite_request(req): | |
727 | '''translate new web interface to traditional format''' |
|
727 | '''translate new web interface to traditional format''' | |
728 |
|
728 | |||
729 | def spliturl(req): |
|
729 | req.url = req.env['SCRIPT_NAME'] | |
730 | def firstitem(query): |
|
730 | if not req.url.endswith('/'): | |
731 | return query.split('&', 1)[0].split(';', 1)[0] |
|
731 | req.url += '/' | |
732 |
|
732 | if req.env.has_key('REPO_NAME'): | ||
733 | def normurl(url): |
|
733 | req.url += req.env['REPO_NAME'] + '/' | |
734 | inner = '/'.join([x for x in url.split('/') if x]) |
|
|||
735 | tl = len(url) > 1 and url.endswith('/') and '/' or '' |
|
|||
736 |
|
||||
737 | return '%s%s%s' % (url.startswith('/') and '/' or '', |
|
|||
738 | inner, tl) |
|
|||
739 |
|
734 | |||
740 | root = normurl(urllib.unquote(req.env.get('REQUEST_URI', '').split('?', 1)[0])) |
|
735 | if req.env.get('PATH_INFO'): | |
741 |
p |
|
736 | parts = req.env.get('PATH_INFO').strip('/').split('/') | |
742 | if pi: |
|
737 | repo_parts = req.env.get('REPO_NAME', '').split('/') | |
743 | # strip leading / |
|
738 | if parts[:len(repo_parts)] == repo_parts: | |
744 |
p |
|
739 | parts = parts[len(repo_parts):] | |
745 |
|
|
740 | query = '/'.join(parts) | |
746 | root = root[:root.rfind(pi)] |
|
|||
747 | if req.env.has_key('REPO_NAME'): |
|
|||
748 | rn = req.env['REPO_NAME'] + '/' |
|
|||
749 | root += rn |
|
|||
750 | query = pi[len(rn):] |
|
|||
751 |
|
|
741 | else: | |
752 | query = pi |
|
742 | query = req.env['QUERY_STRING'].split('&', 1)[0] | |
753 | else: |
|
743 | query = query.split(';', 1)[0] | |
754 | root += '?' |
|
|||
755 | query = firstitem(req.env['QUERY_STRING']) |
|
|||
756 |
|
||||
757 | return (root, query) |
|
|||
758 |
|
||||
759 | req.url, query = spliturl(req) |
|
|||
760 |
|
744 | |||
761 | if req.form.has_key('cmd'): |
|
745 | if req.form.has_key('cmd'): | |
762 | # old style |
|
746 | # old style |
@@ -91,15 +91,11 b' class hgwebdir(object):' | |||||
91 | def config(section, name, default=None, untrusted=True): |
|
91 | def config(section, name, default=None, untrusted=True): | |
92 | return parentui.config(section, name, default, untrusted) |
|
92 | return parentui.config(section, name, default, untrusted) | |
93 |
|
93 | |||
94 | url = req.env['REQUEST_URI'].split('?')[0] |
|
94 | url = req.env.get('SCRIPT_NAME', '') | |
95 | if not url.endswith('/'): |
|
95 | if not url.endswith('/'): | |
96 | url += '/' |
|
96 | url += '/' | |
97 | pathinfo = req.env.get('PATH_INFO', '').strip('/') + '/' |
|
|||
98 | base = url[:len(url) - len(pathinfo)] |
|
|||
99 | if not base.endswith('/'): |
|
|||
100 | base += '/' |
|
|||
101 |
|
97 | |||
102 |
staticurl = config('web', 'staticurl') or |
|
98 | staticurl = config('web', 'staticurl') or url + 'static/' | |
103 | if not staticurl.endswith('/'): |
|
99 | if not staticurl.endswith('/'): | |
104 | staticurl += '/' |
|
100 | staticurl += '/' | |
105 |
|
101 | |||
@@ -158,8 +154,10 b' class hgwebdir(object):' | |||||
158 | if u.configbool("web", "hidden", untrusted=True): |
|
154 | if u.configbool("web", "hidden", untrusted=True): | |
159 | continue |
|
155 | continue | |
160 |
|
156 | |||
161 |
|
|
157 | parts = [req.env['PATH_INFO'], name] | |
162 | .replace("//", "/")) + '/' |
|
158 | if req.env['SCRIPT_NAME']: | |
|
159 | parts.insert(0, req.env['SCRIPT_NAME']) | |||
|
160 | url = ('/'.join(parts).replace("//", "/")) + '/' | |||
163 |
|
161 | |||
164 | # update time with local timezone |
|
162 | # update time with local timezone | |
165 | try: |
|
163 | try: |
@@ -84,6 +84,7 b' class _hgwebhandler(object, BaseHTTPServ' | |||||
84 | env['SERVER_NAME'] = self.server.server_name |
|
84 | env['SERVER_NAME'] = self.server.server_name | |
85 | env['SERVER_PORT'] = str(self.server.server_port) |
|
85 | env['SERVER_PORT'] = str(self.server.server_port) | |
86 | env['REQUEST_URI'] = self.path |
|
86 | env['REQUEST_URI'] = self.path | |
|
87 | env['SCRIPT_NAME'] = '' | |||
87 | env['PATH_INFO'] = path_info |
|
88 | env['PATH_INFO'] = path_info | |
88 | env['REMOTE_HOST'] = self.client_address[0] |
|
89 | env['REMOTE_HOST'] = self.client_address[0] | |
89 | env['REMOTE_ADDR'] = self.client_address[0] |
|
90 | env['REMOTE_ADDR'] = self.client_address[0] |
@@ -16,6 +16,9 b' def launch(application):' | |||||
16 | util.set_binary(sys.stdout) |
|
16 | util.set_binary(sys.stdout) | |
17 |
|
17 | |||
18 | environ = dict(os.environ.items()) |
|
18 | environ = dict(os.environ.items()) | |
|
19 | if 'PATH_INFO' not in environ: | |||
|
20 | environ['PATH_INFO'] = '' | |||
|
21 | ||||
19 | environ['wsgi.input'] = sys.stdin |
|
22 | environ['wsgi.input'] = sys.stdin | |
20 | environ['wsgi.errors'] = sys.stderr |
|
23 | environ['wsgi.errors'] = sys.stderr | |
21 | environ['wsgi.version'] = (1, 0) |
|
24 | environ['wsgi.version'] = (1, 0) |
General Comments 0
You need to be logged in to leave comments.
Login now