about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/scadere/listen.py7
-rw-r--r--tst/test_listen.py8
2 files changed, 14 insertions, 1 deletions
diff --git a/src/scadere/listen.py b/src/scadere/listen.py
index aa322ee..dc898d8 100644
--- a/src/scadere/listen.py
+++ b/src/scadere/listen.py
@@ -193,6 +193,11 @@ async def listen(certs, base_url, host, port):  # pragma: no cover
         await server.serve_forever()
 
 
+def with_trailing_slash(base_url):
+    """Return the base URL with a trailing slash."""
+    return base_url if base_url.endswith('/') else f'{base_url}/'
+
+
 def main(arguments=argv[1:]):
     """Launch server."""
     description = ('Serve the TLS certificate expiration feed'
@@ -205,7 +210,7 @@ def main(arguments=argv[1:]):
     parser.add_argument('-v', '--version', action='version',
                         version=f'%(prog)s {__version__}')
     parser.add_argument('certs', metavar='INPUT', type=Path)
-    parser.add_argument('base_url', metavar='URL')
+    parser.add_argument('base_url', metavar='URL', type=with_trailing_slash)
     parser.add_argument('netloc', metavar='[HOST][:PORT]', nargs='?',
                         type=NetLoc(None), default=('localhost', None))
     args = parser.parse_args(arguments)
diff --git a/tst/test_listen.py b/tst/test_listen.py
index 4d49ae2..ea58cc9 100644
--- a/tst/test_listen.py
+++ b/tst/test_listen.py
@@ -241,3 +241,11 @@ async def test_unallowed_method(base_url, request):
                     await writer.drain()
                     response = await reader.readuntil(b'\r\n')
                     assert response == b'HTTP/1.1 405 Method Not Allowed\r\n'
+
+
+@given(urls())
+def test_with_trailing_slash(base_url):
+    if base_url.endswith('/'):
+        assert with_trailing_slash(base_url) == base_url
+    else:
+        assert with_trailing_slash(base_url) == f'{base_url}/'