Commit Graph

428 Commits

Author SHA1 Message Date
Andrew Godwin
a656c9f4c6 Initial refactor to get HTTP working in new style 2017-08-07 14:15:35 +10:00
Tom Turner
a69d69490b Removed a unsed import (urlencode) (#131) 2017-07-30 22:28:08 +12:00
Adam Johnson
79927fbe10 Travis - test on Trusty (#129)
As per [their blog post](https://blog.travis-ci.com/2017-07-11-trusty-as-default-linux-is-coming) they're making it the new default, best to be ahead of the curve.
2017-07-29 14:42:50 +12:00
Andrew Godwin
f3b5d854ca Fix slow hypothesis test 2017-07-24 10:57:47 -07:00
Andrew Godwin
8fd8f794a4 Fixed #128: Could not use file descriptor 0 2017-07-24 10:41:54 -07:00
Andrew Godwin
cf7e7f3924 Fix flaky test that times out on Python 3.5 only 2017-06-16 10:50:20 +08:00
Andrew Godwin
fbb080c600 Releasing 1.3.0 2017-06-16 10:37:30 +08:00
Andrew Godwin
3b4801527d Fixed #123: Add default websocket timeout. 2017-06-12 10:06:54 +08:00
ElRoberto538
c5385fb253 Added websocket_handshake_timeout option/server param
Added an optional parameter to Server and HTTPFactory to allow Autobahn openHandshakeTimeout to be overridden.
2017-06-02 16:08:58 -07:00
Eric Menendez
4ff2384337 Set HTTP Server header to "Daphne" to avoid revealing Autobahn version number. (#122) 2017-05-30 15:56:16 -07:00
Camilo Nova
63d2166320 Fix typo (#120) 2017-05-26 15:13:27 -07:00
John Miller
3683e71afc Fix Minor Typo in CLI Help Message, "WeSocket"->"WebSocket" (#117) 2017-05-23 18:19:11 -07:00
Andrew Godwin
eb195c6004 Don't break if protocol is removed before it's put into reply_protocols 2017-05-15 09:39:03 -07:00
Maik Hoepfel
8787c1dfe2 Check query string for spec conformance again (#112)
This check was skipped because of
https://github.com/django/daphne/issues/110. As this issue is now fixed,
we can re-enable the check again.
2017-05-02 10:23:49 -07:00
Andrew Godwin
a59bd123a9 Fix ws query test 2017-04-29 19:14:25 -07:00
Andrew Godwin
6318bae452 Fixed #110: Use raw WS query string rather than reconstructing it 2017-04-29 19:09:07 -07:00
Maik Hoepfel
2bcec3fe94 Websockets test and unicode fix for Python 2 (#111)
* Python 2 fix for host address

This is a copy of
57051a48cd
for the Websocket protocol.

In Python 2, Twisted returns a byte string for the host address, while
the spec requires a unicode string. A simple cast gives us consistency.

* Test suite for websocket tests

This commit

* introduces some new helpers to test the Websocket protocol
* renames the old ASGITestCase class to ASGIHTTPTestCase, and
  introduces a test case for testing Websockets
* moves some helper methods that are shared between HTTP and Websockets
  into a mutual base class
* uses the new helpers to simplfiy the existing tests
* and adds a couple new tests.
2017-04-28 14:45:07 -07:00
Andrew Godwin
bd03fabce6 Don't log discarded old protocol messages as ERROR 2017-04-04 10:51:42 +02:00
Yoan Blanc
382318b6d2 Run tox tests from travis. (#104) 2017-04-03 15:49:08 +02:00
Andrew Godwin
46656aad24 Releasing version 1.2.0
Includes some test fixes for the new reply channel style.
2017-04-01 15:26:57 +01:00
Andrew Godwin
cddb0aa89e Fix unicode channel names in Python 2 2017-03-28 11:33:53 -07:00
Andrew Godwin
2d2a0cf822 Fix unicode-ness of http version 2017-03-28 11:28:59 -07:00
Andrew Godwin
4a764f7966 Try to handle HTTP version and SSL correctly (plus better errors) 2017-03-28 11:23:51 -07:00
Andrew Godwin
3937489c4a Update Daphne for new process-local channel style 2017-03-27 19:49:50 -07:00
Andrew Godwin
bd9b8d0068 Improve accept flow handling to allow accept: False and match spec 2017-03-27 10:02:35 -07:00
Raul
9f4f057e4c Support websocket options for cli and infinite time to timeouts (#99)
* add websocket timeout and websocket connetion timeout to Cli. Add support for infinite time to websocket timeout and websocket connection timeout

* change test
2017-03-24 20:47:59 -07:00
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
Andrew Godwin
04118cab7e Releasing 1.1.0 2017-03-18 12:38:52 -07:00
Andrew Godwin
2edfe5d7d5 Ah yes, Twisted 17 releases start at 17.1 2017-03-18 12:32:04 -07:00
Andrew Godwin
fa2841c101 Update the other things mentioning Twisted 16.0 2017-03-18 12:30:20 -07:00
Andrew Godwin
5eff45482a Update tox config for Twisted release range 2017-03-18 12:28:02 -07:00
Andrew Godwin
ea7544d8b7 Update README with HTTP/2 details 2017-03-18 12:25:56 -07:00
Andrew Godwin
a925ce32cd Add in HTTP/2 support with right deps and log info 2017-03-18 12:10:20 -07:00
Cory Benfield
e6e4240c0e Implement IProtocolNegotiationFactory. 2017-03-18 10:48:07 -07:00
Cory Benfield
d3f26a6bf2 Add a custom override of buildProtocol. 2017-03-18 10:48:07 -07:00
Andrew Godwin
d86d7dd3c4 Fixed #93: Don't try to send disconnect if it never connected 2017-03-16 19:06:11 -07:00
Artem Malyshev
3cd048d594 Store endpoint listen results. (#92)
* Store endpoint listen results.

* Rename ports to listeners.
2017-03-16 19:04:02 -07:00
Maik Hoepfel
7f92a48293 Full test suite for HTTP requests (#91)
* Add Hypothesis for property-based tests

Hypothesis:
"It works by letting you write tests that assert that
something should be true for every case, not just the ones you happen to
think of."

I think it's well suited for the task of ensuring Daphne conforms to the
ASGI specification.

* Fix accidental cast to byte string under Python 2

While grepping for calls to str(), I found this bit which looks like a
cast to unicode was intended under Python 2.

* ASGITestCase - checking channel messages for spec conformance

This commit introduces a new test case class, with it's main method
assert_valid_http_request_message. The idea is
that this method is a translation of the ASGI spec to code, and can be
used to check channel messages for conformance with that part of the
spec.

I plan to add further methods for other parts of the spec.

* Add Hypothesis strategies for generating HTTP requests

Hypothesis, our framework for test data generation, contains only
general so-called strategies for generating data. This commit adds a few
which will be useful for generating the data for our tests.

Alos see http://hypothesis.readthedocs.io/en/latest/data.html.

* Add and convert tests for HTTP requests

This commit introduces a few Hypothesis tests to test the HTTP request
part of the specification. To keep things organized, I split the
existing tests module into two: one concerned with requests, and one
concerned with responses. I anticipate that we'll also add modules for
chunks and server push later.

daphne already had tests for the HTTP protocol. Some of them I converted
to Hypothesis tests to increase what was tested. Some were also
concerned with HTTP responses, so they were moved to the new response
module. And three tests were concerned with proxy behaviour, which I
wasn't sure about, and I just kept them as-is, but also moved them
to the request tests.

* Fix byte string issue in Python 2

Twisted seems to return a byte string for the client and server IP
address. It is easily rectified by casting to the required unicode
string. Also added a test to ensure this is also handled correctly in
the X-Forwarded-For header parsing.

* Check order of header values

I'm in the process of updating the ASGI spec to require that the order
of header values is kept. To match that work, I'm adding matching
assertions to the tests.

The code unfortunately is not as elegant as I'd like, but then it's only
a result of the underlying HTTP spec.

* Suppress warning about slow test

The kitchen sink test expectedly can be slow. So far it wasn't slow
enough for hypothesis to trigger a warning, but today Travis must've had
a bad day. I think for this test is is acceptable to exceed hypothesis'
warning threshold.
2017-03-14 14:12:07 -07:00
Andrew Godwin
c55bc8a94b Fixed #90: X-Forwarded-For now does v6 address properly
It also now ignores ports, as I can't find a good example of them being put into the XFF header.
2017-02-25 18:18:17 -08:00
Andrew Godwin
360a445f68 Fix missed test 2017-02-16 10:18:32 -08:00
Andrew Godwin
b8c96d7fb2 Fixed #86: Use left-most X-Forwarded-For value. 2017-02-16 10:01:27 -08:00
NotSqrt
80bacf1ea1 Handle both dicts and twisted Headers (#84)
Fix #78
2017-02-14 18:15:00 -08:00
Andrew Godwin
412d9a48dc Releasing version 1.0.3 2017-02-12 22:44:38 -08:00
Andrew Godwin
b65140b158 Fix WebSockets to work with Twisted 17.1
Underlying PR that broke things: https://github.com/twisted/twisted/pull/591
We're relying on a private API so this is not really Twisted's fault.
2017-02-12 18:25:32 -08:00
Andrew Godwin
9853bf1740 Remove call to receive_many 2017-02-11 16:29:04 -08:00
Andrew Godwin
ecf88ee72a Fix broken proxy util code 2017-02-11 16:27:29 -08:00
Andrew Godwin
7d1123d39a Further fix for #78 and the shared util function 2017-02-11 06:59:43 -08:00
Gennady Chibisov
630609fce7 IPV6 interface binding (#80) 2017-02-10 18:24:50 -08:00
Andrew Godwin
4d23655b5c Fixed #78: Use right variable for WS headers 2017-02-10 09:52:16 -08:00
Andrew Godwin
60952b34bf Releasing version 1.0.2 2017-02-01 12:09:21 -08:00