##// 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 324 if handled:
325 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 332 query = req.dispatchpath
329 333 else:
330 334 query = req.querystring.partition('&')[0].partition(';')[0]
@@ -138,11 +138,12 b' class parsedrequest(object):'
138 138 apppath = attr.ib()
139 139 # List of path parts to be used for dispatch.
140 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 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 147 # The name of the repository being accessed.
147 148 reponame = attr.ib()
148 149 # Raw query string (part after "?" in URL).
@@ -246,12 +247,18 b' def parserequestfromenv(env, bodyfh, rep'
246 247
247 248 apppath = apppath.rstrip('/') + repoprefix
248 249 dispatchparts = dispatchpath.strip('/').split('/')
249 elif env.get('PATH_INFO', '').strip('/'):
250 dispatchparts = env['PATH_INFO'].strip('/').split('/')
250 dispatchpath = '/'.join(dispatchparts)
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 259 else:
252 260 dispatchparts = []
253
254 dispatchpath = '/'.join(dispatchparts)
261 dispatchpath = None
255 262
256 263 querystring = env.get('QUERY_STRING', '')
257 264
@@ -293,7 +300,6 b' def parserequestfromenv(env, bodyfh, rep'
293 300 remotehost=env.get('REMOTE_HOST'),
294 301 apppath=apppath,
295 302 dispatchparts=dispatchparts, dispatchpath=dispatchpath,
296 havepathinfo='PATH_INFO' in env,
297 303 reponame=reponame,
298 304 querystring=querystring,
299 305 qsparams=qsparams,
@@ -42,8 +42,7 b' class ParseRequestTests(unittest.TestCas'
42 42 self.assertIsNone(r.remotehost)
43 43 self.assertEqual(r.apppath, b'')
44 44 self.assertEqual(r.dispatchparts, [])
45 self.assertEqual(r.dispatchpath, b'')
46 self.assertFalse(r.havepathinfo)
45 self.assertIsNone(r.dispatchpath)
47 46 self.assertIsNone(r.reponame)
48 47 self.assertEqual(r.querystring, b'')
49 48 self.assertEqual(len(r.qsparams), 0)
@@ -90,8 +89,7 b' class ParseRequestTests(unittest.TestCas'
90 89 self.assertEqual(r.advertisedbaseurl, b'http://testserver')
91 90 self.assertEqual(r.apppath, b'')
92 91 self.assertEqual(r.dispatchparts, [])
93 self.assertEqual(r.dispatchpath, b'')
94 self.assertFalse(r.havepathinfo)
92 self.assertIsNone(r.dispatchpath)
95 93
96 94 r = parse(DEFAULT_ENV, extra={
97 95 r'SCRIPT_NAME': r'/script',
@@ -103,8 +101,7 b' class ParseRequestTests(unittest.TestCas'
103 101 self.assertEqual(r.advertisedbaseurl, b'http://testserver')
104 102 self.assertEqual(r.apppath, b'/script')
105 103 self.assertEqual(r.dispatchparts, [])
106 self.assertEqual(r.dispatchpath, b'')
107 self.assertFalse(r.havepathinfo)
104 self.assertIsNone(r.dispatchpath)
108 105
109 106 r = parse(DEFAULT_ENV, extra={
110 107 r'SCRIPT_NAME': r'/multiple words',
@@ -116,8 +113,7 b' class ParseRequestTests(unittest.TestCas'
116 113 self.assertEqual(r.advertisedbaseurl, b'http://testserver')
117 114 self.assertEqual(r.apppath, b'/multiple words')
118 115 self.assertEqual(r.dispatchparts, [])
119 self.assertEqual(r.dispatchpath, b'')
120 self.assertFalse(r.havepathinfo)
116 self.assertIsNone(r.dispatchpath)
121 117
122 118 def testpathinfo(self):
123 119 r = parse(DEFAULT_ENV, extra={
@@ -131,7 +127,6 b' class ParseRequestTests(unittest.TestCas'
131 127 self.assertEqual(r.apppath, b'')
132 128 self.assertEqual(r.dispatchparts, [])
133 129 self.assertEqual(r.dispatchpath, b'')
134 self.assertTrue(r.havepathinfo)
135 130
136 131 r = parse(DEFAULT_ENV, extra={
137 132 r'PATH_INFO': r'/pathinfo',
@@ -144,7 +139,6 b' class ParseRequestTests(unittest.TestCas'
144 139 self.assertEqual(r.apppath, b'')
145 140 self.assertEqual(r.dispatchparts, [b'pathinfo'])
146 141 self.assertEqual(r.dispatchpath, b'pathinfo')
147 self.assertTrue(r.havepathinfo)
148 142
149 143 r = parse(DEFAULT_ENV, extra={
150 144 r'PATH_INFO': r'/one/two/',
@@ -157,7 +151,6 b' class ParseRequestTests(unittest.TestCas'
157 151 self.assertEqual(r.apppath, b'')
158 152 self.assertEqual(r.dispatchparts, [b'one', b'two'])
159 153 self.assertEqual(r.dispatchpath, b'one/two')
160 self.assertTrue(r.havepathinfo)
161 154
162 155 def testscriptandpathinfo(self):
163 156 r = parse(DEFAULT_ENV, extra={
@@ -172,7 +165,6 b' class ParseRequestTests(unittest.TestCas'
172 165 self.assertEqual(r.apppath, b'/script')
173 166 self.assertEqual(r.dispatchparts, [b'pathinfo'])
174 167 self.assertEqual(r.dispatchpath, b'pathinfo')
175 self.assertTrue(r.havepathinfo)
176 168
177 169 r = parse(DEFAULT_ENV, extra={
178 170 r'SCRIPT_NAME': r'/script1/script2',
@@ -188,7 +180,6 b' class ParseRequestTests(unittest.TestCas'
188 180 self.assertEqual(r.apppath, b'/script1/script2')
189 181 self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
190 182 self.assertEqual(r.dispatchpath, b'path1/path2')
191 self.assertTrue(r.havepathinfo)
192 183
193 184 r = parse(DEFAULT_ENV, extra={
194 185 r'HTTP_HOST': r'hostserver',
@@ -203,7 +194,6 b' class ParseRequestTests(unittest.TestCas'
203 194 self.assertEqual(r.apppath, b'/script')
204 195 self.assertEqual(r.dispatchparts, [b'pathinfo'])
205 196 self.assertEqual(r.dispatchpath, b'pathinfo')
206 self.assertTrue(r.havepathinfo)
207 197
208 198 def testreponame(self):
209 199 """repository path components get stripped from URL."""
@@ -236,7 +226,6 b' class ParseRequestTests(unittest.TestCas'
236 226 self.assertEqual(r.apppath, b'/repo')
237 227 self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
238 228 self.assertEqual(r.dispatchpath, b'path1/path2')
239 self.assertTrue(r.havepathinfo)
240 229 self.assertEqual(r.reponame, b'repo')
241 230
242 231 r = parse(DEFAULT_ENV, reponame=b'prefix/repo', extra={
@@ -251,7 +240,6 b' class ParseRequestTests(unittest.TestCas'
251 240 self.assertEqual(r.apppath, b'/prefix/repo')
252 241 self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
253 242 self.assertEqual(r.dispatchpath, b'path1/path2')
254 self.assertTrue(r.havepathinfo)
255 243 self.assertEqual(r.reponame, b'prefix/repo')
256 244
257 245 if __name__ == '__main__':
General Comments 0
You need to be logged in to leave comments. Login now