diff --git a/sanic/response.py b/sanic/response.py index bb3a1f9d..9ec2d91a 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -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 diff --git a/sanic/server.py b/sanic/server.py index 62a4c1a7..6d924374 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -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')