Commit Graph

1022 Commits

Author SHA1 Message Date
Andrew Godwin
a9062e5d28 Further clarify accept flow 2017-03-27 09:59:42 -07:00
Andrew Godwin
cf788a3d7d Allow accept to be False 2017-03-27 09:54:30 -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
Flavio Curella
0f0c74daaa Expose WebSocketBridge.socket (#572)
* made `WebSocketBridge._socket` public

We can provide a convenient way to hook custom behavior (such as debugging) by making the underlying `ReconnectingWebSocket` instance publicly available.

Also removed the undocumented `onopen` constructor option.

* recompile js
2017-03-24 15:33:55 -07:00
Erwin Junge
613153cbc6 Allow runworker to be used without staticfiles (#569)
* Allow runworker to be used without staticfiles

* Split too long line

* Reset binding_classes at start of runworker tests
2017-03-23 16:32:51 -07:00
Flavio Curella
10398780a3 Allow relative url in WebsocketBridge.connect() (#567)
* Add support for relative urls in javascript wrapper

* recompile static file

* add js smoke test for relative urls

* update docs to show relative urls
2017-03-23 16:30:28 -07:00
Erwin Junge
4323a64e33 Add python 3.6 checks (#571)
* Add python 3.6 checking to tox

* Add python 3.6 checking to travis
2017-03-23 14:14:15 -07:00
Flavio Curella
9f7fb7b80d remove spurious markdown formatting (#566) 2017-03-23 09:49:17 -07:00
Coread
08ff57ac9b Channel and http session from http (#564)
* Add a new auth decorator to get the user and rehydrate the http session

* Add http_user_and_session, taking precedence over http_user, applying the channel_and_http_session_user_from_http decorator (a superset of http user functionality)

* Only set session cookies on the first send, since subsequent real requests don't have access to HTTP information

* Add a test for new http_user_and_session WebsocketConsumer attribute

* Fix isort check
2017-03-22 15:58:35 -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
526ad65e73 A couple more spec tweaks 2017-03-19 12:32:43 -07:00
Andrew Godwin
1f2538f5b8 Few more spec clarifications 2017-03-19 12:26:20 -07:00
Andrew Godwin
528cd89f4e Rearrange ASGI specs into a proper split of messaging/protocols 2017-03-19 12:17:13 -07:00
Andrew Godwin
274a5a8c98 Releasing 1.1.1 2017-03-19 11:23:28 -07:00
Andrew Godwin
08881bc7de Releasing 1.1.0 2017-03-18 13:04:12 -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
Flavio Curella
63dc5f6651 add Channels WebSocket javascript wrapper (#544)
Adds a WebSocket wrapper which is both publishable to npm and importable directly for use with staticfiles/etc. Also has a new build process to make the latter file.
2017-03-14 15:08:04 -07:00
Erwin Junge
463d16f3f9 Make the channel_session decorator work on methods as well (#555) 2017-03-14 14:14:20 -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
cad63451f8 Expand more on accepting connections 2017-03-12 21:03:44 -07:00
Maik Hoepfel
13c1fcb654 Proposal for minor spec changes (#554)
* Webserver -> web server

This was flagged by my spell check, and indeed it's hard to find
spellings online without the space. The Oxford Dictionary only knows it
with a space, so I thought it's worth correcting.

* Attempt to clarify optional keys

I wasn't sure about how to treat keys marked optional. After having
spoken to Andrew, this is my attempt at clarifying. Improvements
welcome!

* Order of header values MUST be kept

Order for HTTP header values matters, both in request and responses. So
we must make sure that we're keeping it.

Request:
> Some headers, such as Accept-Language can be sent by clients as
> several headers each with a different value rather than sending the
> header as a comma separated list.

http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getHeaders%28java.lang.String%29

Response:
Set-Cookie may be present multiple times, and only the last given value
is to be used.

I'm updating the Daphne test to verify the order in my pull request
there.

* Clarify that headers is a list of lists

The wording for 'server'/'client' and 'headers' was very similar, and I
was unsure if clients may be a list of lists (in anticipation of
protocols supporting that). I hope this small tweak makes it clearer
that only headers is a list of lists.
2017-03-07 23:05:28 -08:00
Doug Keen
2101f285cb Allow custom json encoder and decoder in JsonWebsocketConsumer (#535)
Lets you override the JSON encoding on both the consumer and the multiplexer.
2017-02-28 18:51:48 -08: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
ef6d526359 Add note about installing Redis 2017-02-25 18:12:32 -08:00
Andrew Godwin
c14caede51 Start working on 1.1.0 release notes 2017-02-23 18:01:28 -08:00
Andrew Godwin
b2842f1ef1 Fixed #542: Don't use staticfiles handler if staticfiles is not installed 2017-02-23 17:52:07 -08:00
Pierre Chiquet
7ab21c4846 Set self.kwargs in Binding.trigger_inbound when setting self.message (#541)
Allows options passed in (like a consumer) to be accessible to further code.
2017-02-23 10:17:43 -08:00
Coread
863b1cebdd Requeue next message immediately to avoid wait queue race condition (#532)
Changes the strategy so that after a message has been put on the wait queue, it is then checked to see if it became the next message during this time and if so, immediately flushed. Will hopefully fix #451.
2017-02-22 11:00:50 -08:00
Hassen ben tanfous
db3a020122 Use domain instead of port in docs (#539) 2017-02-20 15:11:28 -08:00
Hassen ben tanfous
7625ed2700 use domain instead of port (#537)
i think this is a typo, as cookies aren't restricted by port, so even if you offload on the same domain, daphne will still work without having to specify a ``session_key`` GET parameter since it can read the django session cookie which it defaults to.
2017-02-19 16:16:37 -08:00
Artem Malyshev
672de2b2a3 Separate tests into own directory. (#531)
* Move project tests to its own directory.

* Install mock test dependency for Python2 only.

* Do not install tox inside tox environment.

* Exclude tests from sdist.

* Use recent pip on Travis-CI.
2017-02-16 10:22:23 -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
Хасанов Булат
13472369eb fix tox (#516) 2017-02-14 09:50:01 -08:00
Pierre Chiquet
95c9925fe4 Update Binding to support models with UUIDField as primary key (#528)
* Add custom TestUUIDModel for auto tests

* Update Binding to support models with UUIDField as primary key

Add and fix test_trigger_outbound_create_non_auto_pk.
Before updating pre_save_receiver, this new test failed with this error:

======================================================================
FAIL: test_trigger_outbound_create_non_auto_pk
(channels.tests.test_binding.TestsBinding)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\User\git\contribs\python\channels\channels\tests\test_binding.py", line 85, in test_trigger_outbound_create_non_auto_pk
    self.assertEqual(received['payload']['action'], 'create')
AssertionError: u'update' != u'create'
2017-02-14 09:48: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
Pablo Oubiña
4185798731 Typo in Example using class-based consumer (#526)
Typo in Example using class-based consumer from section "2.6.3 WebSocket Multiplexing"
2017-02-11 16:41:36 -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