##// END OF EJS Templates
hgweb: change how dispatch path is reported...
Gregory Szorc -
r36914:d0b0fedb default
parent child Browse files
Show More
@@ -324,7 +324,11 b' class hgweb(object):'
324 if handled:
324 if handled:
325 return res.sendresponse()
325 return res.sendresponse()
326
326
327 if req.havepathinfo:
327 # Old implementations of hgweb supported dispatching the request via
328 # the initial query string parameter instead of using PATH_INFO.
329 # If PATH_INFO is present (signaled by ``req.dispatchpath`` having
330 # a value), we use it. Otherwise fall back to the query string.
331 if req.dispatchpath is not None:
328 query = req.dispatchpath
332 query = req.dispatchpath
329 else:
333 else:
330 query = req.querystring.partition('&')[0].partition(';')[0]
334 query = req.querystring.partition('&')[0].partition(';')[0]
@@ -138,11 +138,12 b' class parsedrequest(object):'
138 apppath = attr.ib()
138 apppath = attr.ib()
139 # List of path parts to be used for dispatch.
139 # List of path parts to be used for dispatch.
140 dispatchparts = attr.ib()
140 dispatchparts = attr.ib()
141 # URL path component (no query string) used for dispatch.
141 # URL path component (no query string) used for dispatch. Can be
142 # ``None`` to signal no path component given to the request, an
143 # empty string to signal a request to the application's root URL,
144 # or a string not beginning with ``/`` containing the requested
145 # path under the application.
142 dispatchpath = attr.ib()
146 dispatchpath = attr.ib()
143 # Whether there is a path component to this request. This can be true
144 # when ``dispatchpath`` is empty due to REPO_NAME muckery.
145 havepathinfo = attr.ib()
146 # The name of the repository being accessed.
147 # The name of the repository being accessed.
147 reponame = attr.ib()
148 reponame = attr.ib()
148 # Raw query string (part after "?" in URL).
149 # Raw query string (part after "?" in URL).
@@ -246,12 +247,18 b' def parserequestfromenv(env, bodyfh, rep'
246
247
247 apppath = apppath.rstrip('/') + repoprefix
248 apppath = apppath.rstrip('/') + repoprefix
248 dispatchparts = dispatchpath.strip('/').split('/')
249 dispatchparts = dispatchpath.strip('/').split('/')
249 elif env.get('PATH_INFO', '').strip('/'):
250 dispatchpath = '/'.join(dispatchparts)
250 dispatchparts = env['PATH_INFO'].strip('/').split('/')
251
252 elif 'PATH_INFO' in env:
253 if env['PATH_INFO'].strip('/'):
254 dispatchparts = env['PATH_INFO'].strip('/').split('/')
255 dispatchpath = '/'.join(dispatchparts)
256 else:
257 dispatchparts = []
258 dispatchpath = ''
251 else:
259 else:
252 dispatchparts = []
260 dispatchparts = []
253
261 dispatchpath = None
254 dispatchpath = '/'.join(dispatchparts)
255
262
256 querystring = env.get('QUERY_STRING', '')
263 querystring = env.get('QUERY_STRING', '')
257
264
@@ -293,7 +300,6 b' def parserequestfromenv(env, bodyfh, rep'
293 remotehost=env.get('REMOTE_HOST'),
300 remotehost=env.get('REMOTE_HOST'),
294 apppath=apppath,
301 apppath=apppath,
295 dispatchparts=dispatchparts, dispatchpath=dispatchpath,
302 dispatchparts=dispatchparts, dispatchpath=dispatchpath,
296 havepathinfo='PATH_INFO' in env,
297 reponame=reponame,
303 reponame=reponame,
298 querystring=querystring,
304 querystring=querystring,
299 qsparams=qsparams,
305 qsparams=qsparams,
@@ -42,8 +42,7 b' class ParseRequestTests(unittest.TestCas'
42 self.assertIsNone(r.remotehost)
42 self.assertIsNone(r.remotehost)
43 self.assertEqual(r.apppath, b'')
43 self.assertEqual(r.apppath, b'')
44 self.assertEqual(r.dispatchparts, [])
44 self.assertEqual(r.dispatchparts, [])
45 self.assertEqual(r.dispatchpath, b'')
45 self.assertIsNone(r.dispatchpath)
46 self.assertFalse(r.havepathinfo)
47 self.assertIsNone(r.reponame)
46 self.assertIsNone(r.reponame)
48 self.assertEqual(r.querystring, b'')
47 self.assertEqual(r.querystring, b'')
49 self.assertEqual(len(r.qsparams), 0)
48 self.assertEqual(len(r.qsparams), 0)
@@ -90,8 +89,7 b' class ParseRequestTests(unittest.TestCas'
90 self.assertEqual(r.advertisedbaseurl, b'http://testserver')
89 self.assertEqual(r.advertisedbaseurl, b'http://testserver')
91 self.assertEqual(r.apppath, b'')
90 self.assertEqual(r.apppath, b'')
92 self.assertEqual(r.dispatchparts, [])
91 self.assertEqual(r.dispatchparts, [])
93 self.assertEqual(r.dispatchpath, b'')
92 self.assertIsNone(r.dispatchpath)
94 self.assertFalse(r.havepathinfo)
95
93
96 r = parse(DEFAULT_ENV, extra={
94 r = parse(DEFAULT_ENV, extra={
97 r'SCRIPT_NAME': r'/script',
95 r'SCRIPT_NAME': r'/script',
@@ -103,8 +101,7 b' class ParseRequestTests(unittest.TestCas'
103 self.assertEqual(r.advertisedbaseurl, b'http://testserver')
101 self.assertEqual(r.advertisedbaseurl, b'http://testserver')
104 self.assertEqual(r.apppath, b'/script')
102 self.assertEqual(r.apppath, b'/script')
105 self.assertEqual(r.dispatchparts, [])
103 self.assertEqual(r.dispatchparts, [])
106 self.assertEqual(r.dispatchpath, b'')
104 self.assertIsNone(r.dispatchpath)
107 self.assertFalse(r.havepathinfo)
108
105
109 r = parse(DEFAULT_ENV, extra={
106 r = parse(DEFAULT_ENV, extra={
110 r'SCRIPT_NAME': r'/multiple words',
107 r'SCRIPT_NAME': r'/multiple words',
@@ -116,8 +113,7 b' class ParseRequestTests(unittest.TestCas'
116 self.assertEqual(r.advertisedbaseurl, b'http://testserver')
113 self.assertEqual(r.advertisedbaseurl, b'http://testserver')
117 self.assertEqual(r.apppath, b'/multiple words')
114 self.assertEqual(r.apppath, b'/multiple words')
118 self.assertEqual(r.dispatchparts, [])
115 self.assertEqual(r.dispatchparts, [])
119 self.assertEqual(r.dispatchpath, b'')
116 self.assertIsNone(r.dispatchpath)
120 self.assertFalse(r.havepathinfo)
121
117
122 def testpathinfo(self):
118 def testpathinfo(self):
123 r = parse(DEFAULT_ENV, extra={
119 r = parse(DEFAULT_ENV, extra={
@@ -131,7 +127,6 b' class ParseRequestTests(unittest.TestCas'
131 self.assertEqual(r.apppath, b'')
127 self.assertEqual(r.apppath, b'')
132 self.assertEqual(r.dispatchparts, [])
128 self.assertEqual(r.dispatchparts, [])
133 self.assertEqual(r.dispatchpath, b'')
129 self.assertEqual(r.dispatchpath, b'')
134 self.assertTrue(r.havepathinfo)
135
130
136 r = parse(DEFAULT_ENV, extra={
131 r = parse(DEFAULT_ENV, extra={
137 r'PATH_INFO': r'/pathinfo',
132 r'PATH_INFO': r'/pathinfo',
@@ -144,7 +139,6 b' class ParseRequestTests(unittest.TestCas'
144 self.assertEqual(r.apppath, b'')
139 self.assertEqual(r.apppath, b'')
145 self.assertEqual(r.dispatchparts, [b'pathinfo'])
140 self.assertEqual(r.dispatchparts, [b'pathinfo'])
146 self.assertEqual(r.dispatchpath, b'pathinfo')
141 self.assertEqual(r.dispatchpath, b'pathinfo')
147 self.assertTrue(r.havepathinfo)
148
142
149 r = parse(DEFAULT_ENV, extra={
143 r = parse(DEFAULT_ENV, extra={
150 r'PATH_INFO': r'/one/two/',
144 r'PATH_INFO': r'/one/two/',
@@ -157,7 +151,6 b' class ParseRequestTests(unittest.TestCas'
157 self.assertEqual(r.apppath, b'')
151 self.assertEqual(r.apppath, b'')
158 self.assertEqual(r.dispatchparts, [b'one', b'two'])
152 self.assertEqual(r.dispatchparts, [b'one', b'two'])
159 self.assertEqual(r.dispatchpath, b'one/two')
153 self.assertEqual(r.dispatchpath, b'one/two')
160 self.assertTrue(r.havepathinfo)
161
154
162 def testscriptandpathinfo(self):
155 def testscriptandpathinfo(self):
163 r = parse(DEFAULT_ENV, extra={
156 r = parse(DEFAULT_ENV, extra={
@@ -172,7 +165,6 b' class ParseRequestTests(unittest.TestCas'
172 self.assertEqual(r.apppath, b'/script')
165 self.assertEqual(r.apppath, b'/script')
173 self.assertEqual(r.dispatchparts, [b'pathinfo'])
166 self.assertEqual(r.dispatchparts, [b'pathinfo'])
174 self.assertEqual(r.dispatchpath, b'pathinfo')
167 self.assertEqual(r.dispatchpath, b'pathinfo')
175 self.assertTrue(r.havepathinfo)
176
168
177 r = parse(DEFAULT_ENV, extra={
169 r = parse(DEFAULT_ENV, extra={
178 r'SCRIPT_NAME': r'/script1/script2',
170 r'SCRIPT_NAME': r'/script1/script2',
@@ -188,7 +180,6 b' class ParseRequestTests(unittest.TestCas'
188 self.assertEqual(r.apppath, b'/script1/script2')
180 self.assertEqual(r.apppath, b'/script1/script2')
189 self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
181 self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
190 self.assertEqual(r.dispatchpath, b'path1/path2')
182 self.assertEqual(r.dispatchpath, b'path1/path2')
191 self.assertTrue(r.havepathinfo)
192
183
193 r = parse(DEFAULT_ENV, extra={
184 r = parse(DEFAULT_ENV, extra={
194 r'HTTP_HOST': r'hostserver',
185 r'HTTP_HOST': r'hostserver',
@@ -203,7 +194,6 b' class ParseRequestTests(unittest.TestCas'
203 self.assertEqual(r.apppath, b'/script')
194 self.assertEqual(r.apppath, b'/script')
204 self.assertEqual(r.dispatchparts, [b'pathinfo'])
195 self.assertEqual(r.dispatchparts, [b'pathinfo'])
205 self.assertEqual(r.dispatchpath, b'pathinfo')
196 self.assertEqual(r.dispatchpath, b'pathinfo')
206 self.assertTrue(r.havepathinfo)
207
197
208 def testreponame(self):
198 def testreponame(self):
209 """repository path components get stripped from URL."""
199 """repository path components get stripped from URL."""
@@ -236,7 +226,6 b' class ParseRequestTests(unittest.TestCas'
236 self.assertEqual(r.apppath, b'/repo')
226 self.assertEqual(r.apppath, b'/repo')
237 self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
227 self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
238 self.assertEqual(r.dispatchpath, b'path1/path2')
228 self.assertEqual(r.dispatchpath, b'path1/path2')
239 self.assertTrue(r.havepathinfo)
240 self.assertEqual(r.reponame, b'repo')
229 self.assertEqual(r.reponame, b'repo')
241
230
242 r = parse(DEFAULT_ENV, reponame=b'prefix/repo', extra={
231 r = parse(DEFAULT_ENV, reponame=b'prefix/repo', extra={
@@ -251,7 +240,6 b' class ParseRequestTests(unittest.TestCas'
251 self.assertEqual(r.apppath, b'/prefix/repo')
240 self.assertEqual(r.apppath, b'/prefix/repo')
252 self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
241 self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
253 self.assertEqual(r.dispatchpath, b'path1/path2')
242 self.assertEqual(r.dispatchpath, b'path1/path2')
254 self.assertTrue(r.havepathinfo)
255 self.assertEqual(r.reponame, b'prefix/repo')
243 self.assertEqual(r.reponame, b'prefix/repo')
256
244
257 if __name__ == '__main__':
245 if __name__ == '__main__':
General Comments 0
You need to be logged in to leave comments. Login now