mirror of
https://github.com/django/django.git
synced 2024-11-30 07:06:18 +01:00
Simplified serializing HTTP response headers.
Since ResponseHeaders was introduced, header names and values are stored as strings. There is no need to check whether they are bytes. Co-authored-by: Nick Pope <nick@nickpope.me.uk>
This commit is contained in:
parent
947bdec60c
commit
f03ba0ad52
@ -153,14 +153,10 @@ class HttpResponseBase:
|
||||
|
||||
def serialize_headers(self):
|
||||
"""HTTP headers as a bytestring."""
|
||||
def to_bytes(val, encoding):
|
||||
return val if isinstance(val, bytes) else val.encode(encoding)
|
||||
|
||||
headers = [
|
||||
(to_bytes(key, 'ascii') + b': ' + to_bytes(value, 'latin-1'))
|
||||
return b'\r\n'.join([
|
||||
key.encode('ascii') + b': ' + value.encode('latin-1')
|
||||
for key, value in self.headers.items()
|
||||
]
|
||||
return b'\r\n'.join(headers)
|
||||
])
|
||||
|
||||
__bytes__ = serialize_headers
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user