diff --git a/setup.cfg b/setup.cfg index 62ebeae..af12e9a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = httpaste-victorykit -version = 1.0.5-alpha +version = 1.0.6-alpha author = Tiara Rodney author_email = t.rodney@victoryk.it description = a versatile HTTP pastebin diff --git a/src/httpaste/__init__.py b/src/httpaste/__init__.py index 6eea5ba..3a4cb21 100755 --- a/src/httpaste/__init__.py +++ b/src/httpaste/__init__.py @@ -143,6 +143,7 @@ from inspect import isclass from configparser import ConfigParser from ast import literal_eval from io import StringIO +from os import environ from connexion import FlaskApp from connexion.resolver import RestyResolver @@ -158,7 +159,7 @@ from httpaste.helper.http import ( UnauthorizedError) -CONFIGPATH_ENVIRON = 'HTTPASTE_CONFIG' +CONFIGPATH_ENVIRON = 'HTTPASTE_CONFIGPATH' def get_sanitized_config_charset(charset: str): @@ -198,17 +199,17 @@ class ServerConfig: bind_address = None -def get_config_path(environ: str = CONFIGPATH_ENVIRON): +def get_config_path(var_name: str = CONFIGPATH_ENVIRON): """ """ try: - return os.environ[environ] + return environ[var_name] except KeyError as e: raise ConfigError( - 'environment variable \'{environ}\' not set.') from e + f'environment variable \'{var_name}\' not set.') from e def load_config(path: str) -> Tuple[Config, ServerConfig]: @@ -322,6 +323,14 @@ def get_flask_app( with application.app.app_context(): application.app.httpaste = config + #add header for browsers to present a sign-in prompt + @application.app.after_request + def rewrite_forbidden_request(response): + + if response.status_code in [401]: + response.headers['WWW-Authenticate'] = 'Basic realm="private"' + return response + return application diff --git a/src/httpaste/wsgi.py b/src/httpaste/wsgi.py index e45f821..9e43ff0 100755 --- a/src/httpaste/wsgi.py +++ b/src/httpaste/wsgi.py @@ -3,6 +3,6 @@ """ from httpaste import load_config, get_flask_app, get_config_path -config, server_config = load_config(get_config_path) +config, server_config = load_config(get_config_path()) application = get_flask_app(config, server_config)