Skip to content
Snippets Groups Projects
Unverified Commit be2e5ba0 authored by Andrej Shadura's avatar Andrej Shadura
Browse files

Log the HTTP port for all requests, not just where auth required


On the contrary, we don’t care about logging ports for WebSockets.

It would be a bit more efficient to store the detected port into
g.port here and reuse it later in require_auth(), but OTOH that
would make the tests for require_auth a bit more complicated, since
before_request decorators are not automatically imported.

Signed-off-by: default avatarAndrej Shadura <andrew.shadura@collabora.co.uk>
parent dee9855a
No related branches found
No related tags found
1 merge request!47Fix path-prefixed proxies
......@@ -88,15 +88,21 @@ ws_connections = {}
jobs = bidict()
@app.before_request
@ext_resources.before_request
async def log_port():
_, port = request.scope['server']
structlog.contextvars.bind_contextvars(
http_port=port,
)
def require_auth(f):
"""Require authentication when accessed over the external server port"""
@functools.wraps(f)
async def wrapper(*args, **kwargs):
ctx = request if has_request_context() else websocket
_, port = ctx.scope['server']
structlog.contextvars.bind_contextvars(
http_port=port,
)
if port == config.server.port:
if not ctx.authorization:
return 'auth required', 401, {'WWW-Authenticate': 'Basic'}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment