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