comparison mercurial/hgweb/request.py @ 36904:d0b0fedbfb53

hgweb: change how dispatch path is reported When I implemented the new request object, I carried forward some ugly hacks until I could figure out what was happening. One of those was the handling of PATH_INFO to determine how to route hgweb requests. Essentially, if we have PATH_INFO data, we route according to that. But if we don't, we route by the query string. I question if we still need to support query string routing. But that's for another day, I suppose. In this commit, we clean up the ugly "havepathinfo" hack and replace it with a "dispatchpath" attribute that can hold None or empty string to differentiate between the presence of PATH_INFO. This is still a bit hacky. But at least the request parsing and routing code is explicit about the meaning now. Differential Revision: https://phab.mercurial-scm.org/D2820
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 11 Mar 2018 13:38:56 -0700
parents d7fd203e36cc
children e67a2e05fa8a
comparison
equal deleted inserted replaced
36903:d7fd203e36cc 36904:d0b0fedbfb53
136 remotehost = attr.ib() 136 remotehost = attr.ib()
137 # WSGI application path. 137 # WSGI application path.
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).
149 querystring = attr.ib() 150 querystring = attr.ib()
150 # multidict of query string parameters. 151 # multidict of query string parameters.
244 'not end at path delimiter: %s (%s)' % 245 'not end at path delimiter: %s (%s)' %
245 (env['PATH_INFO'], reponame)) 246 (env['PATH_INFO'], reponame))
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
258 # We store as a list so we have ordering information. We also store as 265 # We store as a list so we have ordering information. We also store as
259 # a dict to facilitate fast lookup. 266 # a dict to facilitate fast lookup.
291 urlscheme=env['wsgi.url_scheme'], 298 urlscheme=env['wsgi.url_scheme'],
292 remoteuser=env.get('REMOTE_USER'), 299 remoteuser=env.get('REMOTE_USER'),
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,
300 headers=headers, 306 headers=headers,
301 bodyfh=bodyfh) 307 bodyfh=bodyfh)