# HG changeset patch # User Thomas De Schampheleire # Date 1537216449 -7200 # Node ID 3d39e68ff5bce9eeaaa9650f449613235cc17fb6 # Parent d8b23000aad675e4435352b4749774d90a0f7ca4 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. diff -r d8b23000aad6 -r 3d39e68ff5bc kallithea/lib/helpers.py --- 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 diff -r d8b23000aad6 -r 3d39e68ff5bc kallithea/tests/other/test_libs.py --- 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