Revert "Revert "Replaced COMMON_STATUS_CODES with a simple 200 check for more fast""
This reverts commit d8df095
This commit is contained in:
parent
f4f6cc15c2
commit
85b1c080aa
|
@ -1,4 +1,4 @@
|
||||||
from sanic.response import ALL_STATUS_CODES, COMMON_STATUS_CODES
|
from sanic.response import STATUS_CODES
|
||||||
|
|
||||||
TRACEBACK_STYLE = '''
|
TRACEBACK_STYLE = '''
|
||||||
<style>
|
<style>
|
||||||
|
@ -275,8 +275,7 @@ def abort(status_code, message=None):
|
||||||
in response.py for the given status code.
|
in response.py for the given status code.
|
||||||
"""
|
"""
|
||||||
if message is None:
|
if message is None:
|
||||||
message = COMMON_STATUS_CODES.get(status_code,
|
message = STATUS_CODES.get(status_code)
|
||||||
ALL_STATUS_CODES.get(status_code))
|
|
||||||
# These are stored as bytes in the STATUS_CODES dict
|
# These are stored as bytes in the STATUS_CODES dict
|
||||||
message = message.decode('utf8')
|
message = message.decode('utf8')
|
||||||
sanic_exception = _sanic_exceptions.get(status_code, SanicException)
|
sanic_exception = _sanic_exceptions.get(status_code, SanicException)
|
||||||
|
|
|
@ -10,13 +10,7 @@ from aiofiles import open as open_async
|
||||||
|
|
||||||
from sanic.cookies import CookieJar
|
from sanic.cookies import CookieJar
|
||||||
|
|
||||||
COMMON_STATUS_CODES = {
|
STATUS_CODES = {
|
||||||
200: b'OK',
|
|
||||||
400: b'Bad Request',
|
|
||||||
404: b'Not Found',
|
|
||||||
500: b'Internal Server Error',
|
|
||||||
}
|
|
||||||
ALL_STATUS_CODES = {
|
|
||||||
100: b'Continue',
|
100: b'Continue',
|
||||||
101: b'Switching Protocols',
|
101: b'Switching Protocols',
|
||||||
102: b'Processing',
|
102: b'Processing',
|
||||||
|
@ -162,11 +156,10 @@ class StreamingHTTPResponse(BaseHTTPResponse):
|
||||||
|
|
||||||
headers = self._parse_headers()
|
headers = self._parse_headers()
|
||||||
|
|
||||||
# Try to pull from the common codes first
|
if self.status is 200:
|
||||||
# Speeds up response rate 6% over pulling from all
|
status = b'OK'
|
||||||
status = COMMON_STATUS_CODES.get(self.status)
|
else:
|
||||||
if not status:
|
status = STATUS_CODES.get(self.status)
|
||||||
status = ALL_STATUS_CODES.get(self.status)
|
|
||||||
|
|
||||||
return (b'HTTP/%b %d %b\r\n'
|
return (b'HTTP/%b %d %b\r\n'
|
||||||
b'%b'
|
b'%b'
|
||||||
|
@ -209,11 +202,10 @@ class HTTPResponse(BaseHTTPResponse):
|
||||||
|
|
||||||
headers = self._parse_headers()
|
headers = self._parse_headers()
|
||||||
|
|
||||||
# Try to pull from the common codes first
|
if self.status is 200:
|
||||||
# Speeds up response rate 6% over pulling from all
|
status = b'OK'
|
||||||
status = COMMON_STATUS_CODES.get(self.status)
|
else:
|
||||||
if not status:
|
status = STATUS_CODES.get(self.status, b'UNKNOWN RESPONSE')
|
||||||
status = ALL_STATUS_CODES.get(self.status, b'UNKNOWN RESPONSE')
|
|
||||||
|
|
||||||
return (b'HTTP/%b %d %b\r\n'
|
return (b'HTTP/%b %d %b\r\n'
|
||||||
b'Connection: %b\r\n'
|
b'Connection: %b\r\n'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user