Mercurial > public > mercurial-scm > hg-stable
diff 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 |
line wrap: on
line diff
--- a/mercurial/hgweb/request.py Sun Mar 11 13:11:13 2018 -0700 +++ b/mercurial/hgweb/request.py Sun Mar 11 13:38:56 2018 -0700 @@ -138,11 +138,12 @@ apppath = attr.ib() # List of path parts to be used for dispatch. dispatchparts = attr.ib() - # URL path component (no query string) used for dispatch. + # URL path component (no query string) used for dispatch. Can be + # ``None`` to signal no path component given to the request, an + # empty string to signal a request to the application's root URL, + # or a string not beginning with ``/`` containing the requested + # path under the application. dispatchpath = attr.ib() - # Whether there is a path component to this request. This can be true - # when ``dispatchpath`` is empty due to REPO_NAME muckery. - havepathinfo = attr.ib() # The name of the repository being accessed. reponame = attr.ib() # Raw query string (part after "?" in URL). @@ -246,12 +247,18 @@ apppath = apppath.rstrip('/') + repoprefix dispatchparts = dispatchpath.strip('/').split('/') - elif env.get('PATH_INFO', '').strip('/'): - dispatchparts = env['PATH_INFO'].strip('/').split('/') + dispatchpath = '/'.join(dispatchparts) + + elif 'PATH_INFO' in env: + if env['PATH_INFO'].strip('/'): + dispatchparts = env['PATH_INFO'].strip('/').split('/') + dispatchpath = '/'.join(dispatchparts) + else: + dispatchparts = [] + dispatchpath = '' else: dispatchparts = [] - - dispatchpath = '/'.join(dispatchparts) + dispatchpath = None querystring = env.get('QUERY_STRING', '') @@ -293,7 +300,6 @@ remotehost=env.get('REMOTE_HOST'), apppath=apppath, dispatchparts=dispatchparts, dispatchpath=dispatchpath, - havepathinfo='PATH_INFO' in env, reponame=reponame, querystring=querystring, qsparams=qsparams,