Add an option to override the external URL scheme

This commit is contained in:
Correl Roush 2021-07-15 21:14:40 -04:00
parent b4a788826b
commit eb2d9e5186
2 changed files with 21 additions and 2 deletions

View file

@ -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,
}

View file

@ -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: