daphne/daphne
Maik Hoepfel d68461920f HTTP responses: two fixes and some tests (#96)
* Fix: Always call Request.write()

The spec says 'content' is an optional key, defaulting to b''.
But before this commit, if 'content' wasn't specified, Request.write()
was not called. In conjunction with setting 'more_content' to True,
this would result in nothing being written on the transport. If
'content' was set to b'' instead, the HTTP preamble and any headers were
written as expected. That smells like a bug, so I'm making sure we're
always calling Request.write().

* Require status key in first message to response channel

Previous to this commit, it was possible to not pass in a 'status' key.
This would result in any passed in headers being ignored as well.

Instead of relying on user data ('status' being present or not), this
commit now enforces that the first message to a response channel is
indead a HTTP Response-style message, and hence contains status. It will
complain loudly if that isn't the case.

* Helper for getting HTTP Response for a given channel message

To test Daphne's message-to-HTTP part, we need an easy way to fetch the
HTTP response for a given response channel message. I borrowed the
approach from Andrew's existing code. I feel like we might be able to do
with less scaffolding at some point, but didn't have time to
investigate. It's good enough for now.

* Add assert method to check a response for spec conformance

Similarly to the method for checking HTTP requests for spec conformance,
we're adding a method to do the same for HTTP responses. This one is a bit
less exciting because we're testing raw HTTP responses.

* Add Hypothesis tests for HTTP responses

Similarly to what I did for HTTP requests, this commit adds a couple
test that try to check different parts of the ASGI spec. Because going
from message to HTTP response is more straightforward than going from
HTTP request to channel message, there's not a whole lot going on here.
2017-03-22 15:55:28 -07:00
..
tests HTTP responses: two fixes and some tests (#96) 2017-03-22 15:55:28 -07:00
twisted/plugins use twisted endpoint description strings to bind to ports and sockets 2016-08-11 17:52:27 +02:00
__init__.py Releasing 1.1.0 2017-03-18 12:38:52 -07:00
access.py Switch to new explicit WebSocket acceptance 2016-10-05 13:45:12 -07:00
cli.py fix tests 2016-11-14 11:04:09 +01:00
http_protocol.py HTTP responses: two fixes and some tests (#96) 2017-03-22 15:55:28 -07:00
server.py Add in HTTP/2 support with right deps and log info 2017-03-18 12:10:20 -07:00
utils.py Fixed #90: X-Forwarded-For now does v6 address properly 2017-02-25 18:18:17 -08:00
ws_protocol.py Fixed #78: Use right variable for WS headers 2017-02-10 09:52:16 -08:00