Replaced COMMON_STATUS_CODES with a simple 200 check for more fast

This commit is contained in:
David Tan 2017-10-17 14:20:41 -04:00
parent 794128a053
commit 15b6980a1a
2 changed files with 11 additions and 20 deletions

View File

@ -1,4 +1,4 @@
from sanic.response import ALL_STATUS_CODES, COMMON_STATUS_CODES
from sanic.response import STATUS_CODES
TRACEBACK_STYLE = '''
<style>
@ -275,8 +275,7 @@ def abort(status_code, message=None):
in response.py for the given status code.
"""
if message is None:
message = COMMON_STATUS_CODES.get(status_code,
ALL_STATUS_CODES.get(status_code))
message = STATUS_CODES.get(status_code)
# These are stored as bytes in the STATUS_CODES dict
message = message.decode('utf8')
sanic_exception = _sanic_exceptions.get(status_code, SanicException)

View File

@ -10,13 +10,7 @@ from aiofiles import open as open_async
from sanic.cookies import CookieJar
COMMON_STATUS_CODES = {
200: b'OK',
400: b'Bad Request',
404: b'Not Found',
500: b'Internal Server Error',
}
ALL_STATUS_CODES = {
STATUS_CODES = {
100: b'Continue',
101: b'Switching Protocols',
102: b'Processing',
@ -162,11 +156,10 @@ class StreamingHTTPResponse(BaseHTTPResponse):
headers = self._parse_headers()
# Try to pull from the common codes first
# Speeds up response rate 6% over pulling from all
status = COMMON_STATUS_CODES.get(self.status)
if not status:
status = ALL_STATUS_CODES.get(self.status)
if self.status is 200:
status = b'OK'
else:
status = STATUS_CODES.get(self.status)
return (b'HTTP/%b %d %b\r\n'
b'%b'
@ -209,11 +202,10 @@ class HTTPResponse(BaseHTTPResponse):
headers = self._parse_headers()
# Try to pull from the common codes first
# Speeds up response rate 6% over pulling from all
status = COMMON_STATUS_CODES.get(self.status)
if not status:
status = ALL_STATUS_CODES.get(self.status, b'UNKNOWN RESPONSE')
if self.status is 200:
status = b'OK'
else:
status = STATUS_CODES.get(self.status, b'UNKNOWN RESPONSE')
return (b'HTTP/%b %d %b\r\n'
b'Connection: %b\r\n'