Skip to content

Commit

Permalink
Merge pull request #391 from scidsg/onion-location
Browse files Browse the repository at this point in the history
Add the Onion-Location header to HTTP responses
  • Loading branch information
micahflee authored Jul 8, 2024
2 parents 901c363 + 582cbb7 commit 92c494a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion hushline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import timedelta
from typing import Any

from flask import Flask, flash, redirect, session, url_for
from flask import Flask, flash, redirect, request, session, url_for
from flask_migrate import Migrate
from werkzeug.wrappers.response import Response

Expand Down Expand Up @@ -33,6 +33,7 @@ def create_app() -> Flask:
app.config["SESSION_COOKIE_HTTPONLY"] = True
app.config["SESSION_COOKIE_SAMESITE"] = "Lax"
app.config["PERMANENT_SESSION_LIFETIME"] = timedelta(minutes=30)
app.config["ONION_HOSTNAME"] = os.environ.get("ONION_HOSTNAME", None)

# Run migrations
db.init_app(app)
Expand All @@ -54,4 +55,14 @@ def inject_user() -> dict[str, Any]:
return {"user": user}
return {}

# Add Onion-Location header to all responses
if app.config["ONION_HOSTNAME"]:

@app.after_request
def add_onion_location_header(response: Response) -> Response:
response.headers["Onion-Location"] = (
f"https://{app.config['ONION_HOSTNAME']}{request.path}"
)
return response

return app

0 comments on commit 92c494a

Please sign in to comment.