mirror of
https://github.com/django/daphne.git
synced 2024-11-21 15:36:33 +03:00
Move to "body" everywhere in HTTP messages
This commit is contained in:
parent
44c1d0905f
commit
26fa870540
|
@ -207,13 +207,13 @@ class WebRequest(http.Request):
|
|||
header = header.encode("latin1")
|
||||
self.responseHeaders.addRawHeader(header, value)
|
||||
logger.debug("HTTP %s response started for %s", message["status"], self.client_addr)
|
||||
elif message["type"] == "http.response.content":
|
||||
elif message["type"] == "http.response.body":
|
||||
if not self._response_started:
|
||||
raise ValueError("HTTP response has not yet been started but got %s" % message["type"])
|
||||
# Write out body
|
||||
http.Request.write(self, message.get("content", b""))
|
||||
http.Request.write(self, message.get("body", b""))
|
||||
# End if there's no more content
|
||||
if not message.get("more_content", False):
|
||||
if not message.get("more_body", False):
|
||||
self.finish()
|
||||
logger.debug("HTTP response complete for %s", self.client_addr)
|
||||
try:
|
||||
|
@ -281,8 +281,8 @@ class WebRequest(http.Request):
|
|||
],
|
||||
})
|
||||
self.handle_reply({
|
||||
"type": "http.response.content",
|
||||
"content": (self.error_template % {
|
||||
"type": "http.response.body",
|
||||
"body": (self.error_template % {
|
||||
"title": six.text_type(status) + " " + status_text.decode("ascii"),
|
||||
"body": body,
|
||||
}).encode("utf8"),
|
||||
|
|
1
setup.py
1
setup.py
|
@ -34,6 +34,7 @@ setup(
|
|||
"tests": [
|
||||
"hypothesis",
|
||||
"pytest",
|
||||
"pytest-asyncio~=0.8",
|
||||
],
|
||||
},
|
||||
entry_points={"console_scripts": [
|
||||
|
|
|
@ -160,7 +160,7 @@ class DaphneTestCase(unittest.TestCase):
|
|||
xff=xff,
|
||||
responses=[
|
||||
{"type": "http.response.start", "status": 200},
|
||||
{"type": "http.response.content", "content": b"OK"},
|
||||
{"type": "http.response.body", "body": b"OK"},
|
||||
],
|
||||
)
|
||||
return scope, messages
|
||||
|
|
|
@ -83,7 +83,7 @@ class TestHTTPRequest(DaphneTestCase):
|
|||
# Check overall keys
|
||||
self.assert_key_sets(
|
||||
required_keys={"type"},
|
||||
optional_keys={"body", "more_content"},
|
||||
optional_keys={"body", "more_body"},
|
||||
actual_keys=message.keys(),
|
||||
)
|
||||
# Check that it is the right type
|
||||
|
|
|
@ -31,8 +31,8 @@ class TestHTTPResponse(DaphneTestCase):
|
|||
"status": 200,
|
||||
},
|
||||
{
|
||||
"type": "http.response.content",
|
||||
"content": b"hello world",
|
||||
"type": "http.response.body",
|
||||
"body": b"hello world",
|
||||
},
|
||||
])
|
||||
self.assertEqual(response.status, 200)
|
||||
|
@ -51,8 +51,8 @@ class TestHTTPResponse(DaphneTestCase):
|
|||
"type": "http.response.start",
|
||||
},
|
||||
{
|
||||
"type": "http.response.content",
|
||||
"content": b"hello world",
|
||||
"type": "http.response.body",
|
||||
"body": b"hello world",
|
||||
},
|
||||
])
|
||||
|
||||
|
@ -66,8 +66,8 @@ class TestHTTPResponse(DaphneTestCase):
|
|||
"status": 201,
|
||||
},
|
||||
{
|
||||
"type": "http.response.content",
|
||||
"content": b"i made a thing!",
|
||||
"type": "http.response.body",
|
||||
"body": b"i made a thing!",
|
||||
},
|
||||
])
|
||||
self.assertEqual(response.status, 201)
|
||||
|
@ -83,13 +83,13 @@ class TestHTTPResponse(DaphneTestCase):
|
|||
"status": 201,
|
||||
},
|
||||
{
|
||||
"type": "http.response.content",
|
||||
"content": b"chunk 1 ",
|
||||
"more_content": True,
|
||||
"type": "http.response.body",
|
||||
"body": b"chunk 1 ",
|
||||
"more_body": True,
|
||||
},
|
||||
{
|
||||
"type": "http.response.content",
|
||||
"content": b"chunk 2",
|
||||
"type": "http.response.body",
|
||||
"body": b"chunk 2",
|
||||
},
|
||||
])
|
||||
self.assertEqual(response.status, 201)
|
||||
|
@ -105,17 +105,17 @@ class TestHTTPResponse(DaphneTestCase):
|
|||
"status": 201,
|
||||
},
|
||||
{
|
||||
"type": "http.response.content",
|
||||
"content": b"chunk 1 ",
|
||||
"more_content": True,
|
||||
"type": "http.response.body",
|
||||
"body": b"chunk 1 ",
|
||||
"more_body": True,
|
||||
},
|
||||
{
|
||||
"type": "http.response.content",
|
||||
"content": b"chunk 2",
|
||||
"more_content": True,
|
||||
"type": "http.response.body",
|
||||
"body": b"chunk 2",
|
||||
"more_body": True,
|
||||
},
|
||||
{
|
||||
"type": "http.response.content",
|
||||
"type": "http.response.body",
|
||||
},
|
||||
])
|
||||
self.assertEqual(response.status, 201)
|
||||
|
@ -133,8 +133,8 @@ class TestHTTPResponse(DaphneTestCase):
|
|||
"status": 200,
|
||||
},
|
||||
{
|
||||
"type": "http.response.content",
|
||||
"content": body,
|
||||
"type": "http.response.body",
|
||||
"body": body,
|
||||
},
|
||||
])
|
||||
self.assertEqual(response.status, 200)
|
||||
|
@ -151,7 +151,7 @@ class TestHTTPResponse(DaphneTestCase):
|
|||
"headers": self.normalize_headers(headers),
|
||||
},
|
||||
{
|
||||
"type": "http.response.content",
|
||||
"type": "http.response.body",
|
||||
},
|
||||
])
|
||||
# Check headers in a sensible way. Ignore transfer-encoding.
|
||||
|
|
Loading…
Reference in New Issue
Block a user