Mercurial > kallithea
changeset 7375:3d39e68ff5bc
urls: allow canonical_url to contain more than just a hostname
Although the .ini file gives the example:
canonical_url = https://kallithea.example.com/repos
it does not actually work. The '/repos' part is stripped off by the
canonical_url method.
The 'host' entry in the arguments passed to routes.url does not strictly
need to be a pure hostname. At least, the implementation does no validation
of this fact, it is concatenated verbatim between the protocol and the rest
of the URL.
As mapping Kallithea to a subpath of a base hostname is a valid
implementation, the canonical_url feature should allow it.
author | Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> |
---|---|
date | Mon, 17 Sep 2018 22:34:09 +0200 |
parents | d8b23000aad6 |
children | 6bd262eaa058 |
files | kallithea/lib/helpers.py kallithea/tests/other/test_libs.py |
diffstat | 2 files changed, 5 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/helpers.py Mon Sep 17 22:33:57 2018 +0200 +++ b/kallithea/lib/helpers.py Mon Sep 17 22:34:09 2018 +0200 @@ -58,7 +58,7 @@ from kallithea import CONFIG try: parts = CONFIG.get('canonical_url', '').split('://', 1) - kargs['host'] = parts[1].split('/', 1)[0] + kargs['host'] = parts[1] kargs['protocol'] = parts[0] except IndexError: kargs['qualified'] = True
--- a/kallithea/tests/other/test_libs.py Mon Sep 17 22:33:57 2018 +0200 +++ b/kallithea/tests/other/test_libs.py Mon Sep 17 22:34:09 2018 +0200 @@ -559,6 +559,8 @@ ('http://www.example.org', '/abc/xyz/', 'http://www.example.org/abc/xyz/'), ('http://www.example.org', 'abc/xyz/', 'http://www.example.org/abc/xyz/'), ('http://www.example.org', 'about', 'http://www.example.org/about-page'), + ('http://www.example.org/repos/', 'abc/xyz/', 'http://www.example.org/repos/abc/xyz/'), + ('http://www.example.org/kallithea/repos/', 'abc/xyz/', 'http://www.example.org/kallithea/repos/abc/xyz/'), ]) def test_canonical_url(self, canonical, test, expected): from kallithea.lib.helpers import canonical_url @@ -581,6 +583,8 @@ @parametrize('canonical,expected', [ ('http://www.example.org', 'www.example.org'), + ('http://www.example.org/repos/', 'www.example.org'), + ('http://www.example.org/kallithea/repos/', 'www.example.org'), ]) def test_canonical_hostname(self, canonical, expected): from kallithea.lib.helpers import canonical_hostname