From 4571f4eb54ea9ac8b3eb3828fe2fca5bbce7ac67 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Mon, 19 Jul 2021 15:41:23 -0700 Subject: [PATCH] Fix disabling of location header autocorrect for werkzeug 2+ (#647) In werkzeug 2.0.0 and later, the Location header autocorrection moved from BaseResponse to Response, so we need to set `autocorrect_location_header = False` in `Response` not `BaseResponse`. Moreover, `BaseResponse` is gone in werkzeug 2.1.0, hence the try-except block. Signed-off-by: Adam Williamson --- httpbin/core.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/httpbin/core.py b/httpbin/core.py index 305c988..2c72e81 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -29,7 +29,10 @@ from flask import ( from six.moves import range as xrange from werkzeug.datastructures import WWWAuthenticate, MultiDict from werkzeug.http import http_date -from werkzeug.wrappers import BaseResponse +try: + from werkzeug.wrappers import Response as BaseResponse +except ImportError: + from werkzeug.wrappers import BaseResponse from werkzeug.http import parse_authorization_header from flasgger import Swagger, NO_SANITIZER @@ -77,6 +80,9 @@ def jsonify(*args, **kwargs): # Prevent WSGI from correcting the casing of the Location header +# and forcing it to be absolute. This moved from BaseResponse to +# Response in werkzeug 2.0.0, and BaseResponse is gone in werkzeug +# 2.1.0. BaseResponse.autocorrect_location_header = False # Find the correct template folder when running from a different location