Fix header capitalization on input
also removed redundant utf-8 in encodes/decodes
This commit is contained in:
parent
41918eaf0a
commit
ccbbce0036
|
@ -83,10 +83,10 @@ class HTTPResponse:
|
|||
if body is not None:
|
||||
try:
|
||||
# Try to encode it regularly
|
||||
self.body = body.encode('utf-8')
|
||||
self.body = body.encode()
|
||||
except AttributeError:
|
||||
# Convert it to a str if you can't
|
||||
self.body = str(body).encode('utf-8')
|
||||
self.body = str(body).encode()
|
||||
else:
|
||||
self.body = body_bytes
|
||||
|
||||
|
@ -106,11 +106,11 @@ class HTTPResponse:
|
|||
for name, value in self.headers.items():
|
||||
try:
|
||||
headers += (
|
||||
b'%b: %b\r\n' % (name.title().encode(), value.encode('utf-8')))
|
||||
b'%b: %b\r\n' % (name.encode(), value.encode()))
|
||||
except AttributeError:
|
||||
headers += (
|
||||
b'%b: %b\r\n' % (
|
||||
str(name).title().encode(), str(value).encode('utf-8')))
|
||||
str(name).encode(), str(value).encode()))
|
||||
|
||||
# Try to pull from the common codes first
|
||||
# Speeds up response rate 6% over pulling from all
|
||||
|
|
|
@ -136,7 +136,7 @@ class HttpProtocol(asyncio.Protocol):
|
|||
exception = PayloadTooLarge('Payload Too Large')
|
||||
self.write_error(exception)
|
||||
|
||||
self.headers.append((name.decode(), value.decode('utf-8')))
|
||||
self.headers.append((name.decode().casefold(), value.decode()))
|
||||
|
||||
def on_headers_complete(self):
|
||||
remote_addr = self.transport.get_extra_info('peername')
|
||||
|
|
Loading…
Reference in New Issue
Block a user