mirror of
https://github.com/django/daphne.git
synced 2024-11-29 03:03:44 +03:00
Update to reflect new ASGI spec.
This commit is contained in:
parent
f9a6150aed
commit
a6e11d55a4
|
@ -93,12 +93,13 @@ class WebRequest(http.Request):
|
||||||
# Boring old HTTP.
|
# Boring old HTTP.
|
||||||
else:
|
else:
|
||||||
# Sanitize and decode headers
|
# Sanitize and decode headers
|
||||||
self.clean_headers = {}
|
self.clean_headers = []
|
||||||
for name, value in self.requestHeaders.getAllRawHeaders():
|
for name, values in self.requestHeaders.getAllRawHeaders():
|
||||||
# Prevent CVE-2015-0219
|
# Prevent CVE-2015-0219
|
||||||
if b"_" in name:
|
if b"_" in name:
|
||||||
continue
|
continue
|
||||||
self.clean_headers[name.lower().decode("latin1")] = value[0]
|
for value in values:
|
||||||
|
self.clean_headers.append((name.lower(), value))
|
||||||
logger.debug("HTTP %s request for %s", self.method, self.reply_channel)
|
logger.debug("HTTP %s request for %s", self.method, self.reply_channel)
|
||||||
self.content.seek(0, 0)
|
self.content.seek(0, 0)
|
||||||
# Send message
|
# Send message
|
||||||
|
@ -161,7 +162,10 @@ class WebRequest(http.Request):
|
||||||
self.setResponseCode(message['status'], status_text)
|
self.setResponseCode(message['status'], status_text)
|
||||||
# Write headers
|
# Write headers
|
||||||
for header, value in message.get("headers", {}):
|
for header, value in message.get("headers", {}):
|
||||||
self.setHeader(header.encode("utf8"), value)
|
# Shim code from old ASGI version, can be removed after a while
|
||||||
|
if isinstance(header, six.text_type):
|
||||||
|
header = header.encode("latin1")
|
||||||
|
self.setHeader(header, value)
|
||||||
logger.debug("HTTP %s response started for %s", message['status'], self.reply_channel)
|
logger.debug("HTTP %s response started for %s", message['status'], self.reply_channel)
|
||||||
# Write out body
|
# Write out body
|
||||||
if "content" in message:
|
if "content" in message:
|
||||||
|
@ -194,7 +198,7 @@ class WebRequest(http.Request):
|
||||||
"status": status,
|
"status": status,
|
||||||
"status_text": status_text,
|
"status_text": status_text,
|
||||||
"headers": [
|
"headers": [
|
||||||
("Content-Type", b"text/html; charset=utf-8"),
|
(b"Content-Type", b"text/html; charset=utf-8"),
|
||||||
],
|
],
|
||||||
"content": (self.error_template % {
|
"content": (self.error_template % {
|
||||||
"title": str(status) + " " + status_text.decode("ascii"),
|
"title": str(status) + " " + status_text.decode("ascii"),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user