From a27ebc4697cadf33f6b6c761ee0183a58e2b0126 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Fri, 6 Aug 2021 10:28:56 -0700 Subject: [PATCH] Flask routing tweak, don't redirect URLs with empty path elements --- app.py | 3 +++ redirect.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 2634d85..a0b60c6 100644 --- a/app.py +++ b/app.py @@ -26,6 +26,9 @@ app.url_map.converters['regex'] = flask_util.RegexConverter app.after_request(flask_util.default_modern_headers) app.register_error_handler(Exception, flask_util.handle_exception) +# don't redirect API requests with blank path elements +app.url_map.redirect_defaults = True + app.wsgi_app = handlers.ndb_context_middleware( app.wsgi_app, client=appengine_config.ndb_client) diff --git a/redirect.py b/redirect.py index 462cae4..5fc5c1f 100644 --- a/redirect.py +++ b/redirect.py @@ -31,7 +31,7 @@ CACHE_TIME = datetime.timedelta(seconds=15) @app.get(r'/r/') @cache.cached(timeout=CACHE_TIME.total_seconds(), query_string=True, response_filter=flask_util.not_5xx) -def redir(to=None): +def redir(to): """301 redirect to the embedded fully qualified URL. e.g. redirects /r/https://foo.com/bar?baz to https://foo.com/bar?baz