Replaced COMMON_STATUS_CODES with a simple 200 check for more fast (#982)

* Replaced COMMON_STATUS_CODES with a simple 200 check for more fast

* Added IPware algorithm

* Remove HTTP prefix from Django-style headers
Remove right_most_proxy because it's outside spec

* Remove obvious docstrings

* Revert "Replaced COMMON_STATUS_CODES with a simple 200 check for more fast"

This reverts commit 15b6980

* Revert "Added IPware algorithm"

This reverts commit bdf66cb

WTF HOW DO I GIT

* Revert "Revert "Replaced COMMON_STATUS_CODES with a simple 200 check for more fast""

This reverts commit d8df095

* Revert "Added IPware algorithm"

This reverts commit bdf66cb

* Delete ip.py
This commit is contained in:
davidtgq 2017-10-19 19:43:07 -04:00 committed by Eli Uriegas
parent f721f90add
commit 5bcbc5a337
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 = ''' 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)

View File

@ -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'