diff --git a/tutor/cli.py b/tutor/cli.py index 9f404cd..b4c20da 100644 --- a/tutor/cli.py +++ b/tutor/cli.py @@ -45,13 +45,15 @@ def main(ctx, database, log_level): @main.command() @click.option("--port", type=int, envvar="TUTOR_PORT", default=8888) +@click.option("--scheme", envvar="TUTOR_SCHEME") @click.option("--static", envvar="TUTOR_STATIC", type=click.Path(file_okay=False)) @click.option("--debug", is_flag=True) @click.pass_context -def server(ctx, port, static, debug): +def server(ctx, port, scheme, static, debug): app = tutor.server.make_app( { **ctx.obj, + "scheme": scheme, "static": static, "debug": debug, } diff --git a/tutor/server.py b/tutor/server.py index b195386..d5154b6 100644 --- a/tutor/server.py +++ b/tutor/server.py @@ -30,10 +30,27 @@ def update_args(url: str, **qargs) -> str: class SearchHandler(tornado.web.RequestHandler): + def url(self, url: str) -> str: + scheme_override = self.application.settings["scheme"] + if not scheme_override: + return url + parts = urllib.parse.urlsplit(url) + return urllib.parse.urlunsplit( + ( + scheme_override, + parts.netloc, + parts.path, + parts.query, + parts.fragment, + ) + ) + def set_links(self, **links) -> None: self.set_header( "Link", - ", ".join([f'<{url}>; rel="{rel}"' for rel, url in links.items()]), + ", ".join( + [f'<{self.url(url)}>; rel="{rel}"' for rel, url in links.items()] + ), ) async def get(self) -> None: