Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1848 from ashleysommer/fix_named_response_middleware
Reverse named_response_middlware execution order, to match normal response middleware execution order.
- Loading branch information
Showing
3 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from sanic import Sanic, Blueprint | ||
from sanic.response import text | ||
''' | ||
Demonstrates that blueprint request middleware are executed in the order they | ||
are added. And blueprint response middleware are executed in _reverse_ order. | ||
On a valid request, it should print "1 2 3 6 5 4" to terminal | ||
''' | ||
|
||
app = Sanic(__name__) | ||
|
||
bp = Blueprint("bp_"+__name__) | ||
|
||
@bp.middleware('request') | ||
def request_middleware_1(request): | ||
print('1') | ||
|
||
@bp.middleware('request') | ||
def request_middleware_2(request): | ||
print('2') | ||
|
||
@bp.middleware('request') | ||
def request_middleware_3(request): | ||
print('3') | ||
|
||
@bp.middleware('response') | ||
def resp_middleware_4(request, response): | ||
print('4') | ||
|
||
@bp.middleware('response') | ||
def resp_middleware_5(request, response): | ||
print('5') | ||
|
||
@bp.middleware('response') | ||
def resp_middleware_6(request, response): | ||
print('6') | ||
|
||
@bp.route('/') | ||
def pop_handler(request): | ||
return text('hello world') | ||
|
||
app.blueprint(bp, url_prefix='/bp') | ||
|
||
app.run(host="0.0.0.0", port=8000, debug=True, auto_reload=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters