Minor speed improvements
This commit is contained in:
parent
62c1235f58
commit
ec10d24ac6
@ -97,21 +97,21 @@ class Sanic:
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Middleware process_request
|
# Middleware process_request
|
||||||
response = None
|
response = False
|
||||||
# The if improves speed. I don't know why
|
# The if improves speed. I don't know why
|
||||||
if self.request_middleware:
|
if self.request_middleware:
|
||||||
for middleware in self.request_middleware:
|
for middleware in self.request_middleware:
|
||||||
response = middleware(request)
|
response = middleware(request)
|
||||||
if isawaitable(response):
|
if isawaitable(response):
|
||||||
response = await response
|
response = await response
|
||||||
if response is not None:
|
if response:
|
||||||
break
|
break
|
||||||
|
|
||||||
# No middleware results
|
# No middleware results
|
||||||
if response is None:
|
if not response:
|
||||||
# Fetch handler from router
|
# Fetch handler from router
|
||||||
handler, args, kwargs = self.router.get(request)
|
handler, args, kwargs = self.router.get(request)
|
||||||
if handler is None:
|
if not handler:
|
||||||
raise ServerError("'None' was returned while requesting a handler from the router")
|
raise ServerError("'None' was returned while requesting a handler from the router")
|
||||||
|
|
||||||
# Run response handler
|
# Run response handler
|
||||||
@ -125,7 +125,7 @@ class Sanic:
|
|||||||
_response = middleware(request, response)
|
_response = middleware(request, response)
|
||||||
if isawaitable(_response):
|
if isawaitable(_response):
|
||||||
_response = await _response
|
_response = await _response
|
||||||
if _response is not None:
|
if _response:
|
||||||
response = _response
|
response = _response
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class HttpProtocol(asyncio.Protocol):
|
|||||||
self.loop = loop
|
self.loop = loop
|
||||||
self.transport = None
|
self.transport = None
|
||||||
self.request = None
|
self.request = None
|
||||||
self.parser = None
|
self.parser = False
|
||||||
self.url = None
|
self.url = None
|
||||||
self.headers = None
|
self.headers = None
|
||||||
self.signal = signal
|
self.signal = signal
|
||||||
@ -64,8 +64,7 @@ class HttpProtocol(asyncio.Protocol):
|
|||||||
return self.bail_out("Request too large ({}), connection closed".format(self._total_request_size))
|
return self.bail_out("Request too large ({}), connection closed".format(self._total_request_size))
|
||||||
|
|
||||||
# Create parser if this is the first time we're receiving data
|
# Create parser if this is the first time we're receiving data
|
||||||
if self.parser is None:
|
if not self.parser:
|
||||||
assert self.request is None
|
|
||||||
self.headers = []
|
self.headers = []
|
||||||
self.parser = httptools.HttpRequestParser(self)
|
self.parser = httptools.HttpRequestParser(self)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user