##// END OF EJS Templates
hgweb: support constructing URLs from an alternate base URL...
hgweb: support constructing URLs from an alternate base URL The web.baseurl config option allows server operators to define a custom URL for hosted content. The way it works today is that hgwebdir parses this config option into URL components then updates the appropriate WSGI environment variables so the request "lies" about its details. For example, SERVER_NAME is updated to reflect the alternate base URL's hostname. The WSGI environment should not be modified because WSGI applications may want to know the original request details (for debugging, etc). This commit teaches our request parser about the existence of an alternate base URL. If defined, the advertised URL and other self-reflected paths will take the alternate base URL into account. The hgweb WSGI application didn't use web.baseurl. But hgwebdir did. We update hgwebdir to alter the environment parsing accordingly. The old code around environment manipulation has been removed. With this change, parserequestfromenv() has grown to a bit unwieldy. Now that practically everyone is using it, it is obvious that there is some unused features that can be trimmed. So look for this in follow-up commits. Differential Revision: https://phab.mercurial-scm.org/D2822

File last commit:

r30559:d83ca854 default
r36916:219b2335 default
Show More
test-hgwebdir-paths.py
48 lines | 1.1 KiB | text/x-python | PythonLexer
/ tests / test-hgwebdir-paths.py
Pulkit Goyal
tests: make test-hgwebdir-paths use absolute_import
r28932 from __future__ import absolute_import
Jeremy Whitlock
hgweb: make hgwebdir handle dict/list paths the same as config paths...
r8529 import os
Pulkit Goyal
tests: make test-hgwebdir-paths use absolute_import
r28932 from mercurial import (
hg,
ui as uimod,
)
from mercurial.hgweb import (
hgwebdir_mod,
)
hgwebdir = hgwebdir_mod.hgwebdir
Jeremy Whitlock
hgweb: make hgwebdir handle dict/list paths the same as config paths...
r8529
os.mkdir('webdir')
os.chdir('webdir')
Matt Mackall
backout dbdb777502dc (issue3077) (issue3071)...
r15381 webdir = os.path.realpath('.')
Jeremy Whitlock
hgweb: make hgwebdir handle dict/list paths the same as config paths...
r8529
Yuya Nishihara
ui: factor out ui.load() to create a ui without loading configs (API)...
r30559 u = uimod.ui.load()
Jeremy Whitlock
hgweb: make hgwebdir handle dict/list paths the same as config paths...
r8529 hg.repository(u, 'a', create=1)
hg.repository(u, 'b', create=1)
os.chdir('b')
hg.repository(u, 'd', create=1)
os.chdir('..')
hg.repository(u, 'c', create=1)
os.chdir('..')
paths = {'t/a/': '%s/a' % webdir,
'b': '%s/b' % webdir,
'coll': '%s/*' % webdir,
'rcoll': '%s/**' % webdir}
config = os.path.join(webdir, 'hgwebdir.conf')
configfile = open(config, 'w')
configfile.write('[paths]\n')
for k, v in paths.items():
configfile.write('%s = %s\n' % (k, v))
configfile.close()
confwd = hgwebdir(config)
dictwd = hgwebdir(paths)
assert len(confwd.repos) == len(dictwd.repos), 'different numbers'
assert len(confwd.repos) == 9, 'expected 9 repos, found %d' % len(confwd.repos)
found = dict(confwd.repos)
for key, path in dictwd.repos:
assert key in found, 'repository %s was not found' % key
assert found[key] == path, 'different paths for repo %s' % key