diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-03-27 18:46:16 +0100 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-03-27 19:01:15 +0100 |
commit | 35534d46bef472b1d1cb19ee4c5949823053da2a (patch) | |
tree | 2c1fe22593f7a5535ef4177663b9c48f092f70c7 /paste | |
parent | 4a0a47ce23080142b12832b44e6cd56072c50df2 (diff) | |
download | paste-35534d46bef472b1d1cb19ee4c5949823053da2a.tar.gz paste-35534d46bef472b1d1cb19ee4c5949823053da2a.tar.xz paste-35534d46bef472b1d1cb19ee4c5949823053da2a.zip |
Respond to auth failures with WWW-Authenticate
Diffstat (limited to 'paste')
-rw-r--r-- | paste/__init__.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/paste/__init__.py b/paste/__init__.py index 2ec00a4..c769997 100644 --- a/paste/__init__.py +++ b/paste/__init__.py @@ -36,7 +36,10 @@ DB_PATH = "paste.sqlite3" def simple_response( - start_response: StartResponse, status: str, exc_info: Optional[tuple] = None + start_response: StartResponse, + status: str, + extra_headers: list = list(), + exc_info: Optional[tuple] = None, ) -> Response: body = (status + "\n").encode() start_response( @@ -44,6 +47,7 @@ def simple_response( [ ("Content-Type", "text/plain"), ("Content-Length", str(len(body))), + *extra_headers, ], exc_info, ) @@ -197,7 +201,11 @@ def authenticate(app: App, environ: Env, start_response: StartResponse) -> Respo if environ["REQUEST_METHOD"] in {"GET", "HEAD"} or check_auth(): return app(environ, start_response) - return simple_response(start_response, "401 Unauthorized") + return simple_response( + start_response, + "401 Unauthorized", + extra_headers=[("WWW-Authenticate", "APIKey")], + ) @catch_exceptions |