mirror of
https://github.com/django/daphne.git
synced 2024-11-21 23:46:33 +03:00
Attach path to http.disconnect
https://github.com/andrewgodwin/channels/issues/303
This commit is contained in:
parent
1a5cce9c75
commit
edb67cac74
|
@ -177,6 +177,7 @@ class WebRequest(http.Request):
|
||||||
try:
|
try:
|
||||||
self.factory.channel_layer.send("http.disconnect", {
|
self.factory.channel_layer.send("http.disconnect", {
|
||||||
"reply_channel": self.reply_channel,
|
"reply_channel": self.reply_channel,
|
||||||
|
"path": self.unquote(self.path),
|
||||||
})
|
})
|
||||||
except self.factory.channel_layer.ChannelFull:
|
except self.factory.channel_layer.ChannelFull:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -66,3 +66,30 @@ class TestHTTPProtocol(TestCase):
|
||||||
# Get the resulting message off of the channel layer, check root_path
|
# Get the resulting message off of the channel layer, check root_path
|
||||||
_, message = self.channel_layer.receive_many(["http.request"])
|
_, message = self.channel_layer.receive_many(["http.request"])
|
||||||
self.assertEqual(message['root_path'], "/foobar /bar")
|
self.assertEqual(message['root_path'], "/foobar /bar")
|
||||||
|
|
||||||
|
def test_http_disconnect_sets_path_key(self):
|
||||||
|
"""
|
||||||
|
Tests http disconnect has the path key set, see http://channels.readthedocs.io/en/latest/asgi.html#disconnect
|
||||||
|
"""
|
||||||
|
# Send a simple request to the protocol
|
||||||
|
self.proto.dataReceived(
|
||||||
|
b"GET /te%20st-%C3%A0/?foo=bar HTTP/1.1\r\n" +
|
||||||
|
b"Host: anywhere.com\r\n" +
|
||||||
|
b"\r\n"
|
||||||
|
)
|
||||||
|
# Get the request message
|
||||||
|
_, message = self.channel_layer.receive_many(["http.request"])
|
||||||
|
|
||||||
|
# Send back an example response
|
||||||
|
self.factory.dispatch_reply(
|
||||||
|
message['reply_channel'],
|
||||||
|
{
|
||||||
|
"status": 200,
|
||||||
|
"status_text": b"OK",
|
||||||
|
"content": b"DISCO",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Get the disconnection notification
|
||||||
|
_, disconnect_message = self.channel_layer.receive_many(["http.disconnect"])
|
||||||
|
self.assertEqual(disconnect_message['path'], "/te st-à/")
|
Loading…
Reference in New Issue
Block a user