Skip to content

Commit df733e9

Browse files
committed
fix Werkzeug 2.1.x compatibility
- fix httpbin/core.py: use Responce class instead of BaseResponse see: pallets/werkzeug#2276 - fix tests: TestClient doesn't provide 'Content-Length' header anymore see: pallets/werkzeug#2347
1 parent f8ec666 commit df733e9

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

httpbin/core.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
from six.moves import range as xrange
3030
from werkzeug.datastructures import WWWAuthenticate, MultiDict
3131
from werkzeug.http import http_date
32-
from werkzeug.wrappers import BaseResponse
32+
try:
33+
from werkzeug.wrappers import Response
34+
except ImportError:
35+
from werkzeug.wrappers import BaseResponse as Response
3336
from werkzeug.http import parse_authorization_header
3437
from flasgger import Swagger, NO_SANITIZER
3538

@@ -77,7 +80,7 @@ def jsonify(*args, **kwargs):
7780

7881

7982
# Prevent WSGI from correcting the casing of the Location header
80-
BaseResponse.autocorrect_location_header = False
83+
Response.autocorrect_location_header = False
8184

8285
# Find the correct template folder when running from a different location
8386
tmpl_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates")

test_httpbin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def test_get(self):
148148
data = json.loads(response.data.decode('utf-8'))
149149
self.assertEqual(data['args'], {})
150150
self.assertEqual(data['headers']['Host'], 'localhost')
151-
self.assertEqual(data['headers']['Content-Length'], '0')
151+
# self.assertEqual(data['headers']['Content-Length'], '0')
152152
self.assertEqual(data['headers']['User-Agent'], 'test')
153153
# self.assertEqual(data['origin'], None)
154154
self.assertEqual(data['url'], 'http://localhost/get')
@@ -162,7 +162,7 @@ def test_anything(self):
162162
data = json.loads(response.data.decode('utf-8'))
163163
self.assertEqual(data['args'], {})
164164
self.assertEqual(data['headers']['Host'], 'localhost')
165-
self.assertEqual(data['headers']['Content-Length'], '0')
165+
# self.assertEqual(data['headers']['Content-Length'], '0')
166166
self.assertEqual(data['url'], 'http://localhost/anything/foo/bar')
167167
self.assertEqual(data['method'], 'GET')
168168
self.assertTrue(response.data.endswith(b'\n'))

0 commit comments

Comments
 (0)