Pass the request ctx rather than use the globals in the app

The globals have a performance penalty which can be justified for the
convinience in user code. In the app however the ctx can easily be
passed through the method calls thereby reducing the performance
penalty.

This may affect extensions if they have subclassed the app and
overridden these methods.
This commit is contained in:
pgjones 2023-08-20 21:37:37 +01:00
parent 74d923515c
commit d8262aa58c
5 changed files with 80 additions and 42 deletions

View file

@ -288,8 +288,8 @@ def test_bad_environ_raises_bad_request():
# use a non-printable character in the Host - this is key to this test
environ["HTTP_HOST"] = "\x8a"
with app.request_context(environ):
response = app.full_dispatch_request()
with app.request_context(environ) as ctx:
response = app.full_dispatch_request(ctx)
assert response.status_code == 400
@ -308,8 +308,8 @@ def test_environ_for_valid_idna_completes():
# these characters are all IDNA-compatible
environ["HTTP_HOST"] = "ąśźäüжŠßя.com"
with app.request_context(environ):
response = app.full_dispatch_request()
with app.request_context(environ) as ctx:
response = app.full_dispatch_request(ctx)
assert response.status_code == 200