Show More
@@ -1,150 +1,147 b'' | |||
|
1 | 1 | This tests if hgweb and hgwebdir still work if the REQUEST_URI variable is |
|
2 | 2 | no longer passed with the request. Instead, SCRIPT_NAME and PATH_INFO |
|
3 | 3 | should be used from d74fc8dec2b4 onward to route the request. |
|
4 | 4 | |
|
5 | 5 | $ hg init repo |
|
6 | 6 | $ cd repo |
|
7 | 7 | $ echo foo > bar |
|
8 | 8 | $ hg add bar |
|
9 | 9 | $ hg commit -m "test" |
|
10 | 10 | $ hg tip |
|
11 | 11 | changeset: 0:61c9426e69fe |
|
12 | 12 | tag: tip |
|
13 | 13 | user: test |
|
14 | 14 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
15 | 15 | summary: test |
|
16 | 16 | |
|
17 | 17 | $ cat > request.py <<EOF |
|
18 | 18 | > from __future__ import absolute_import |
|
19 | 19 | > import os |
|
20 | 20 | > import sys |
|
21 |
> from mercurial |
|
|
21 | > from mercurial import ( | |
|
22 | 22 | > hgweb, |
|
23 | > hgwebdir, | |
|
24 | > ) | |
|
25 | > from mercurial import ( | |
|
26 | 23 | > util, |
|
27 | 24 | > ) |
|
28 | 25 | > stringio = util.stringio |
|
29 | 26 | > |
|
30 | 27 | > errors = stringio() |
|
31 | 28 | > input = stringio() |
|
32 | 29 | > |
|
33 | 30 | > def startrsp(status, headers): |
|
34 | 31 | > print('---- STATUS') |
|
35 | 32 | > print(status) |
|
36 | 33 | > print('---- HEADERS') |
|
37 | 34 | > print([i for i in headers if i[0] != 'ETag']) |
|
38 | 35 | > print('---- DATA') |
|
39 | 36 | > sys.stdout.flush() |
|
40 | 37 | > return output.write |
|
41 | 38 | > |
|
42 | 39 | > env = { |
|
43 | 40 | > 'wsgi.version': (1, 0), |
|
44 | 41 | > 'wsgi.url_scheme': 'http', |
|
45 | 42 | > 'wsgi.errors': errors, |
|
46 | 43 | > 'wsgi.input': input, |
|
47 | 44 | > 'wsgi.multithread': False, |
|
48 | 45 | > 'wsgi.multiprocess': False, |
|
49 | 46 | > 'wsgi.run_once': False, |
|
50 | 47 | > 'REQUEST_METHOD': 'GET', |
|
51 | 48 | > 'PATH_INFO': '/', |
|
52 | 49 | > 'SCRIPT_NAME': '', |
|
53 | 50 | > 'SERVER_NAME': '$LOCALIP', |
|
54 | 51 | > 'SERVER_PORT': os.environ['HGPORT'], |
|
55 | 52 | > 'SERVER_PROTOCOL': 'HTTP/1.0' |
|
56 | 53 | > } |
|
57 | 54 | > |
|
58 | 55 | > def process(app): |
|
59 | 56 | > try: |
|
60 | 57 | > stdout = sys.stdout.buffer |
|
61 | 58 | > except AttributeError: |
|
62 | 59 | > stdout = sys.stdout |
|
63 | 60 | > content = app(env, startrsp) |
|
64 | 61 | > stdout.write(output.getvalue()) |
|
65 | 62 | > stdout.write(b''.join(content)) |
|
66 | 63 | > stdout.flush() |
|
67 | 64 | > getattr(content, 'close', lambda : None)() |
|
68 | 65 | > if errors.getvalue(): |
|
69 | 66 | > print('---- ERRORS') |
|
70 | 67 | > print(errors.getvalue()) |
|
71 | 68 | > sys.stdout.flush() |
|
72 | 69 | > |
|
73 | 70 | > output = stringio() |
|
74 | 71 | > env['QUERY_STRING'] = 'style=atom' |
|
75 | > process(hgweb(b'.', name=b'repo')) | |
|
72 | > process(hgweb.hgweb(b'.', name=b'repo')) | |
|
76 | 73 | > |
|
77 | 74 | > output = stringio() |
|
78 | 75 | > env['QUERY_STRING'] = 'style=raw' |
|
79 | > process(hgwebdir({b'repo': b'.'})) | |
|
76 | > process(hgweb.hgwebdir({b'repo': b'.'})) | |
|
80 | 77 | > EOF |
|
81 | 78 | $ "$PYTHON" request.py |
|
82 | 79 | ---- STATUS |
|
83 | 80 | 200 Script output follows |
|
84 | 81 | ---- HEADERS |
|
85 | 82 | [('Content-Type', 'application/atom+xml; charset=ascii')] |
|
86 | 83 | ---- DATA |
|
87 | 84 | <?xml version="1.0" encoding="ascii"?> |
|
88 | 85 | <feed xmlns="http://www.w3.org/2005/Atom"> |
|
89 | 86 | <!-- Changelog --> |
|
90 | 87 | <id>http://$LOCALIP:$HGPORT/</id> (glob) |
|
91 | 88 | <link rel="self" href="http://$LOCALIP:$HGPORT/atom-log"/> (glob) |
|
92 | 89 | <link rel="alternate" href="http://$LOCALIP:$HGPORT/"/> (glob) |
|
93 | 90 | <title>repo Changelog</title> |
|
94 | 91 | <updated>1970-01-01T00:00:00+00:00</updated> |
|
95 | 92 | |
|
96 | 93 | <entry> |
|
97 | 94 | <title>[default] test</title> |
|
98 | 95 | <id>http://$LOCALIP:$HGPORT/#changeset-61c9426e69fef294feed5e2bbfc97d39944a5b1c</id> (glob) |
|
99 | 96 | <link href="http://$LOCALIP:$HGPORT/rev/61c9426e69fe"/> (glob) |
|
100 | 97 | <author> |
|
101 | 98 | <name>test</name> |
|
102 | 99 | <email>test</email> |
|
103 | 100 | </author> |
|
104 | 101 | <updated>1970-01-01T00:00:00+00:00</updated> |
|
105 | 102 | <published>1970-01-01T00:00:00+00:00</published> |
|
106 | 103 | <content type="xhtml"> |
|
107 | 104 | <table xmlns="http://www.w3.org/1999/xhtml"> |
|
108 | 105 | <tr> |
|
109 | 106 | <th style="text-align:left;">changeset</th> |
|
110 | 107 | <td>61c9426e69fe</td> |
|
111 | 108 | </tr> |
|
112 | 109 | <tr> |
|
113 | 110 | <th style="text-align:left;">branch</th> |
|
114 | 111 | <td>default</td> |
|
115 | 112 | </tr> |
|
116 | 113 | <tr> |
|
117 | 114 | <th style="text-align:left;">bookmark</th> |
|
118 | 115 | <td></td> |
|
119 | 116 | </tr> |
|
120 | 117 | <tr> |
|
121 | 118 | <th style="text-align:left;">tag</th> |
|
122 | 119 | <td>tip</td> |
|
123 | 120 | </tr> |
|
124 | 121 | <tr> |
|
125 | 122 | <th style="text-align:left;">user</th> |
|
126 | 123 | <td>test</td> |
|
127 | 124 | </tr> |
|
128 | 125 | <tr> |
|
129 | 126 | <th style="text-align:left;vertical-align:top;">description</th> |
|
130 | 127 | <td>test</td> |
|
131 | 128 | </tr> |
|
132 | 129 | <tr> |
|
133 | 130 | <th style="text-align:left;vertical-align:top;">files</th> |
|
134 | 131 | <td>bar<br /></td> |
|
135 | 132 | </tr> |
|
136 | 133 | </table> |
|
137 | 134 | </content> |
|
138 | 135 | </entry> |
|
139 | 136 | |
|
140 | 137 | </feed> |
|
141 | 138 | ---- STATUS |
|
142 | 139 | 200 Script output follows |
|
143 | 140 | ---- HEADERS |
|
144 | 141 | [('Content-Type', 'text/plain; charset=ascii')] |
|
145 | 142 | ---- DATA |
|
146 | 143 | |
|
147 | 144 | /repo/ |
|
148 | 145 | |
|
149 | 146 | |
|
150 | 147 | $ cd .. |
@@ -1,180 +1,177 b'' | |||
|
1 | 1 | This tests if hgweb and hgwebdir still work if the REQUEST_URI variable is |
|
2 | 2 | no longer passed with the request. Instead, SCRIPT_NAME and PATH_INFO |
|
3 | 3 | should be used from d74fc8dec2b4 onward to route the request. |
|
4 | 4 | |
|
5 | 5 | $ hg init repo |
|
6 | 6 | $ cd repo |
|
7 | 7 | $ echo foo > bar |
|
8 | 8 | $ hg add bar |
|
9 | 9 | $ hg commit -m "test" |
|
10 | 10 | $ hg tip |
|
11 | 11 | changeset: 0:61c9426e69fe |
|
12 | 12 | tag: tip |
|
13 | 13 | user: test |
|
14 | 14 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
15 | 15 | summary: test |
|
16 | 16 | |
|
17 | 17 | $ cat > request.py <<EOF |
|
18 | 18 | > from __future__ import absolute_import |
|
19 | 19 | > import os |
|
20 | 20 | > import sys |
|
21 | > from mercurial.hgweb import ( | |
|
22 | > hgweb, | |
|
23 | > hgwebdir, | |
|
24 | > ) | |
|
25 | 21 | > from mercurial import ( |
|
26 | 22 | > encoding, |
|
23 | > hgweb, | |
|
27 | 24 | > util, |
|
28 | 25 | > ) |
|
29 | 26 | > stringio = util.stringio |
|
30 | 27 | > |
|
31 | 28 | > errors = stringio() |
|
32 | 29 | > input = stringio() |
|
33 | 30 | > |
|
34 | 31 | > def startrsp(status, headers): |
|
35 | 32 | > print('---- STATUS') |
|
36 | 33 | > print(status) |
|
37 | 34 | > print('---- HEADERS') |
|
38 | 35 | > print([i for i in headers if i[0] != 'ETag']) |
|
39 | 36 | > print('---- DATA') |
|
40 | 37 | > return output.write |
|
41 | 38 | > |
|
42 | 39 | > env = { |
|
43 | 40 | > 'wsgi.version': (1, 0), |
|
44 | 41 | > 'wsgi.url_scheme': 'http', |
|
45 | 42 | > 'wsgi.errors': errors, |
|
46 | 43 | > 'wsgi.input': input, |
|
47 | 44 | > 'wsgi.multithread': False, |
|
48 | 45 | > 'wsgi.multiprocess': False, |
|
49 | 46 | > 'wsgi.run_once': False, |
|
50 | 47 | > 'REQUEST_METHOD': 'GET', |
|
51 | 48 | > 'SCRIPT_NAME': '', |
|
52 | 49 | > 'SERVER_NAME': '$LOCALIP', |
|
53 | 50 | > 'SERVER_PORT': os.environ['HGPORT'], |
|
54 | 51 | > 'SERVER_PROTOCOL': 'HTTP/1.0' |
|
55 | 52 | > } |
|
56 | 53 | > |
|
57 | 54 | > def process(app): |
|
58 | 55 | > content = app(env, startrsp) |
|
59 | 56 | > sys.stdout.write(encoding.strfromlocal(output.getvalue())) |
|
60 | 57 | > sys.stdout.write(encoding.strfromlocal(b''.join(content))) |
|
61 | 58 | > getattr(content, 'close', lambda : None)() |
|
62 | 59 | > print('---- ERRORS') |
|
63 | 60 | > print(encoding.strfromlocal(errors.getvalue())) # avoid b'' output diff |
|
64 | 61 | > |
|
65 | 62 | > output = stringio() |
|
66 | 63 | > env['PATH_INFO'] = '/' |
|
67 | 64 | > env['QUERY_STRING'] = 'style=atom' |
|
68 | > process(hgweb(b'.', name = b'repo')) | |
|
65 | > process(hgweb.hgweb(b'.', name = b'repo')) | |
|
69 | 66 | > |
|
70 | 67 | > output = stringio() |
|
71 | 68 | > env['PATH_INFO'] = '/file/tip/' |
|
72 | 69 | > env['QUERY_STRING'] = 'style=raw' |
|
73 | > process(hgweb(b'.', name = b'repo')) | |
|
70 | > process(hgweb.hgweb(b'.', name = b'repo')) | |
|
74 | 71 | > |
|
75 | 72 | > output = stringio() |
|
76 | 73 | > env['PATH_INFO'] = '/' |
|
77 | 74 | > env['QUERY_STRING'] = 'style=raw' |
|
78 | > process(hgwebdir({b'repo': b'.'})) | |
|
75 | > process(hgweb.hgwebdir({b'repo': b'.'})) | |
|
79 | 76 | > |
|
80 | 77 | > output = stringio() |
|
81 | 78 | > env['PATH_INFO'] = '/repo/file/tip/' |
|
82 | 79 | > env['QUERY_STRING'] = 'style=raw' |
|
83 | > process(hgwebdir({b'repo': b'.'})) | |
|
80 | > process(hgweb.hgwebdir({b'repo': b'.'})) | |
|
84 | 81 | > EOF |
|
85 | 82 | $ "$PYTHON" request.py |
|
86 | 83 | ---- STATUS |
|
87 | 84 | 200 Script output follows |
|
88 | 85 | ---- HEADERS |
|
89 | 86 | [('Content-Type', 'application/atom+xml; charset=ascii')] |
|
90 | 87 | ---- DATA |
|
91 | 88 | <?xml version="1.0" encoding="ascii"?> |
|
92 | 89 | <feed xmlns="http://www.w3.org/2005/Atom"> |
|
93 | 90 | <!-- Changelog --> |
|
94 | 91 | <id>http://$LOCALIP:$HGPORT/</id> (glob) |
|
95 | 92 | <link rel="self" href="http://$LOCALIP:$HGPORT/atom-log"/> (glob) |
|
96 | 93 | <link rel="alternate" href="http://$LOCALIP:$HGPORT/"/> (glob) |
|
97 | 94 | <title>repo Changelog</title> |
|
98 | 95 | <updated>1970-01-01T00:00:00+00:00</updated> |
|
99 | 96 | |
|
100 | 97 | <entry> |
|
101 | 98 | <title>[default] test</title> |
|
102 | 99 | <id>http://$LOCALIP:$HGPORT/#changeset-61c9426e69fef294feed5e2bbfc97d39944a5b1c</id> (glob) |
|
103 | 100 | <link href="http://$LOCALIP:$HGPORT/rev/61c9426e69fe"/> (glob) |
|
104 | 101 | <author> |
|
105 | 102 | <name>test</name> |
|
106 | 103 | <email>test</email> |
|
107 | 104 | </author> |
|
108 | 105 | <updated>1970-01-01T00:00:00+00:00</updated> |
|
109 | 106 | <published>1970-01-01T00:00:00+00:00</published> |
|
110 | 107 | <content type="xhtml"> |
|
111 | 108 | <table xmlns="http://www.w3.org/1999/xhtml"> |
|
112 | 109 | <tr> |
|
113 | 110 | <th style="text-align:left;">changeset</th> |
|
114 | 111 | <td>61c9426e69fe</td> |
|
115 | 112 | </tr> |
|
116 | 113 | <tr> |
|
117 | 114 | <th style="text-align:left;">branch</th> |
|
118 | 115 | <td>default</td> |
|
119 | 116 | </tr> |
|
120 | 117 | <tr> |
|
121 | 118 | <th style="text-align:left;">bookmark</th> |
|
122 | 119 | <td></td> |
|
123 | 120 | </tr> |
|
124 | 121 | <tr> |
|
125 | 122 | <th style="text-align:left;">tag</th> |
|
126 | 123 | <td>tip</td> |
|
127 | 124 | </tr> |
|
128 | 125 | <tr> |
|
129 | 126 | <th style="text-align:left;">user</th> |
|
130 | 127 | <td>test</td> |
|
131 | 128 | </tr> |
|
132 | 129 | <tr> |
|
133 | 130 | <th style="text-align:left;vertical-align:top;">description</th> |
|
134 | 131 | <td>test</td> |
|
135 | 132 | </tr> |
|
136 | 133 | <tr> |
|
137 | 134 | <th style="text-align:left;vertical-align:top;">files</th> |
|
138 | 135 | <td>bar<br /></td> |
|
139 | 136 | </tr> |
|
140 | 137 | </table> |
|
141 | 138 | </content> |
|
142 | 139 | </entry> |
|
143 | 140 | |
|
144 | 141 | </feed> |
|
145 | 142 | ---- ERRORS |
|
146 | 143 | |
|
147 | 144 | ---- STATUS |
|
148 | 145 | 200 Script output follows |
|
149 | 146 | ---- HEADERS |
|
150 | 147 | [('Content-Type', 'text/plain; charset=ascii')] |
|
151 | 148 | ---- DATA |
|
152 | 149 | |
|
153 | 150 | -rw-r--r-- 4 bar |
|
154 | 151 | |
|
155 | 152 | |
|
156 | 153 | ---- ERRORS |
|
157 | 154 | |
|
158 | 155 | ---- STATUS |
|
159 | 156 | 200 Script output follows |
|
160 | 157 | ---- HEADERS |
|
161 | 158 | [('Content-Type', 'text/plain; charset=ascii')] |
|
162 | 159 | ---- DATA |
|
163 | 160 | |
|
164 | 161 | /repo/ |
|
165 | 162 | |
|
166 | 163 | ---- ERRORS |
|
167 | 164 | |
|
168 | 165 | ---- STATUS |
|
169 | 166 | 200 Script output follows |
|
170 | 167 | ---- HEADERS |
|
171 | 168 | [('Content-Type', 'text/plain; charset=ascii')] |
|
172 | 169 | ---- DATA |
|
173 | 170 | |
|
174 | 171 | -rw-r--r-- 4 bar |
|
175 | 172 | |
|
176 | 173 | |
|
177 | 174 | ---- ERRORS |
|
178 | 175 | |
|
179 | 176 | |
|
180 | 177 | $ cd .. |
@@ -1,96 +1,94 b'' | |||
|
1 | 1 | Tests if hgweb can run without touching sys.stdin, as is required |
|
2 | 2 | by the WSGI standard and strictly implemented by mod_wsgi. |
|
3 | 3 | |
|
4 | 4 | $ hg init repo |
|
5 | 5 | $ cd repo |
|
6 | 6 | $ echo foo > bar |
|
7 | 7 | $ hg add bar |
|
8 | 8 | $ hg commit -m "test" |
|
9 | 9 | $ cat > request.py <<EOF |
|
10 | 10 | > from __future__ import absolute_import |
|
11 | 11 | > import os |
|
12 | 12 | > import sys |
|
13 | 13 | > from mercurial import ( |
|
14 | 14 | > dispatch, |
|
15 | 15 | > encoding, |
|
16 | 16 | > hg, |
|
17 | 17 | > pycompat, |
|
18 | 18 | > ui as uimod, |
|
19 | 19 | > util, |
|
20 | 20 | > ) |
|
21 | 21 | > ui = uimod.ui |
|
22 |
> from mercurial.hgweb |
|
|
23 | > hgweb, | |
|
24 | > ) | |
|
22 | > from mercurial.hgweb import hgweb_mod | |
|
25 | 23 | > stringio = util.stringio |
|
26 | 24 | > |
|
27 | 25 | > class FileLike(object): |
|
28 | 26 | > def __init__(self, real): |
|
29 | 27 | > self.real = real |
|
30 | 28 | > def fileno(self): |
|
31 | 29 | > print >> sys.__stdout__, 'FILENO' |
|
32 | 30 | > return self.real.fileno() |
|
33 | 31 | > def read(self): |
|
34 | 32 | > print >> sys.__stdout__, 'READ' |
|
35 | 33 | > return self.real.read() |
|
36 | 34 | > def readline(self): |
|
37 | 35 | > print >> sys.__stdout__, 'READLINE' |
|
38 | 36 | > return self.real.readline() |
|
39 | 37 | > |
|
40 | 38 | > sys.stdin = FileLike(sys.stdin) |
|
41 | 39 | > errors = stringio() |
|
42 | 40 | > input = stringio() |
|
43 | 41 | > output = stringio() |
|
44 | 42 | > |
|
45 | 43 | > def startrsp(status, headers): |
|
46 | 44 | > print('---- STATUS') |
|
47 | 45 | > print(status) |
|
48 | 46 | > print('---- HEADERS') |
|
49 | 47 | > print([i for i in headers if i[0] != 'ETag']) |
|
50 | 48 |
|
|
51 | 49 | > return output.write |
|
52 | 50 | > |
|
53 | 51 | > env = { |
|
54 | 52 | > 'wsgi.version': (1, 0), |
|
55 | 53 | > 'wsgi.url_scheme': 'http', |
|
56 | 54 | > 'wsgi.errors': errors, |
|
57 | 55 | > 'wsgi.input': input, |
|
58 | 56 | > 'wsgi.multithread': False, |
|
59 | 57 | > 'wsgi.multiprocess': False, |
|
60 | 58 | > 'wsgi.run_once': False, |
|
61 | 59 | > 'REQUEST_METHOD': 'GET', |
|
62 | 60 | > 'SCRIPT_NAME': '', |
|
63 | 61 | > 'PATH_INFO': '', |
|
64 | 62 | > 'QUERY_STRING': '', |
|
65 | 63 | > 'SERVER_NAME': '$LOCALIP', |
|
66 | 64 | > 'SERVER_PORT': os.environ['HGPORT'], |
|
67 | 65 | > 'SERVER_PROTOCOL': 'HTTP/1.0' |
|
68 | 66 | > } |
|
69 | 67 | > |
|
70 | > i = hgweb(b'.') | |
|
68 | > i = hgweb_mod.hgweb(b'.') | |
|
71 | 69 | > for c in i(env, startrsp): |
|
72 | 70 | > pass |
|
73 | 71 | > sys.stdout.flush() |
|
74 | 72 | > pycompat.stdout.write(b'---- ERRORS\n') |
|
75 | 73 | > pycompat.stdout.write(b'%s\n' % errors.getvalue()) |
|
76 | 74 | > print('---- OS.ENVIRON wsgi variables') |
|
77 | 75 | > print(sorted([x for x in os.environ if x.startswith('wsgi')])) |
|
78 | 76 | > print('---- request.ENVIRON wsgi variables') |
|
79 | 77 | > with i._obtainrepo() as repo: |
|
80 | 78 | > print(sorted([encoding.strfromlocal(x) for x in repo.ui.environ |
|
81 | 79 | > if x.startswith(b'wsgi')])) |
|
82 | 80 | > EOF |
|
83 | 81 | $ "$PYTHON" request.py |
|
84 | 82 | ---- STATUS |
|
85 | 83 | 200 Script output follows |
|
86 | 84 | ---- HEADERS |
|
87 | 85 | [('Content-Type', 'text/html; charset=ascii')] |
|
88 | 86 | ---- DATA |
|
89 | 87 | ---- ERRORS |
|
90 | 88 | |
|
91 | 89 | ---- OS.ENVIRON wsgi variables |
|
92 | 90 | [] |
|
93 | 91 | ---- request.ENVIRON wsgi variables |
|
94 | 92 | ['wsgi.errors', 'wsgi.input', 'wsgi.multiprocess', 'wsgi.multithread', 'wsgi.run_once', 'wsgi.url_scheme', 'wsgi.version'] |
|
95 | 93 | |
|
96 | 94 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now