speed improvements
This commit is contained in:
parent
33f712ef9b
commit
62c1235f58
|
@ -98,12 +98,14 @@ class Sanic:
|
||||||
try:
|
try:
|
||||||
# Middleware process_request
|
# Middleware process_request
|
||||||
response = None
|
response = None
|
||||||
for middleware in self.request_middleware:
|
# The if improves speed. I don't know why
|
||||||
response = middleware(request)
|
if self.request_middleware:
|
||||||
if isawaitable(response):
|
for middleware in self.request_middleware:
|
||||||
response = await response
|
response = middleware(request)
|
||||||
if response is not None:
|
if isawaitable(response):
|
||||||
break
|
response = await response
|
||||||
|
if response is not None:
|
||||||
|
break
|
||||||
|
|
||||||
# No middleware results
|
# No middleware results
|
||||||
if response is None:
|
if response is None:
|
||||||
|
@ -118,13 +120,14 @@ class Sanic:
|
||||||
response = await response
|
response = await response
|
||||||
|
|
||||||
# Middleware process_response
|
# Middleware process_response
|
||||||
for middleware in self.response_middleware:
|
if self.response_middleware:
|
||||||
_response = middleware(request, response)
|
for middleware in self.response_middleware:
|
||||||
if isawaitable(_response):
|
_response = middleware(request, response)
|
||||||
_response = await _response
|
if isawaitable(_response):
|
||||||
if _response is not None:
|
_response = await _response
|
||||||
response = _response
|
if _response is not None:
|
||||||
break
|
response = _response
|
||||||
|
break
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -14,8 +14,4 @@ app = Sanic("test")
|
||||||
async def test(request):
|
async def test(request):
|
||||||
return json({ "test": True })
|
return json({ "test": True })
|
||||||
|
|
||||||
@app.route("/file")
|
|
||||||
async def test(request):
|
|
||||||
return json({ "test": True, "files": request.files, "fields": request.form })
|
|
||||||
|
|
||||||
app.run(host="0.0.0.0", port=sys.argv[1])
|
app.run(host="0.0.0.0", port=sys.argv[1])
|
Loading…
Reference in New Issue
Block a user