From f17a65b5c0c340fd188cba5c374a16a92edd4515 Mon Sep 17 00:00:00 2001 From: yguarata Date: Thu, 14 Apr 2016 08:33:35 -0300 Subject: [PATCH 1/9] Adding WEBSOCKET_HOST to settings. The setting WEBSOCKET_HOST enables using Websockets in cross domains. This is, the websocket domain (e.g. ws.myapp.com) is different from the site domain (e.g. www.myapp.com). However, it is mandatory to provide the Django setting SESSION_COOKIE_DOMAIN (e.g. SESSION_COOKIE_DOMAIN = '.myapp.com'). --- ws4redis/context_processors.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ws4redis/context_processors.py b/ws4redis/context_processors.py index 7238b0e3..9cd16724 100644 --- a/ws4redis/context_processors.py +++ b/ws4redis/context_processors.py @@ -7,10 +7,11 @@ def default(request): """ Adds additional context variables to the default context. """ + host = settings.WEBSOCKET_HOST or request.get_host() protocol = request.is_secure() and 'wss://' or 'ws://' heartbeat_msg = settings.WS4REDIS_HEARTBEAT and '"{0}"'.format(settings.WS4REDIS_HEARTBEAT) or 'null' context = { - 'WEBSOCKET_URI': protocol + request.get_host() + settings.WEBSOCKET_URL, + 'WEBSOCKET_URI': protocol + host + settings.WEBSOCKET_URL, 'WS4REDIS_HEARTBEAT': mark_safe(heartbeat_msg), } return context From 36e048f6c1c5682a6527ee49088722c1652df852 Mon Sep 17 00:00:00 2001 From: yguarata Date: Thu, 14 Apr 2016 08:33:37 -0300 Subject: [PATCH 2/9] Adding WEBSOCKET_HOST to settings. The setting WEBSOCKET_HOST enables using Websockets in cross domains. This is, the websocket domain (e.g. ws.myapp.com) is different from the site domain (e.g. www.myapp.com). However, it is mandatory to provide the Django setting SESSION_COOKIE_DOMAIN (e.g. SESSION_COOKIE_DOMAIN = '.myapp.com'). --- ws4redis/settings.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ws4redis/settings.py b/ws4redis/settings.py index 18fda6a8..d1ba2016 100644 --- a/ws4redis/settings.py +++ b/ws4redis/settings.py @@ -3,6 +3,12 @@ WEBSOCKET_URL = getattr(settings, 'WEBSOCKET_URL', '/ws/') +""" +The host addres that will be listening for Websocket connections. If not provided, +it will be used the same host as of the site. +""" +WEBSOCKET_HOST = getattr(settings, 'WEBSOCKET_HOST', None) + WS4REDIS_CONNECTION = getattr(settings, 'WS4REDIS_CONNECTION', { 'host': 'localhost', 'port': 6379, From 0c14f5650839052a7788e5b69c6404e73f3e7271 Mon Sep 17 00:00:00 2001 From: yguarata Date: Thu, 14 Apr 2016 08:42:31 -0300 Subject: [PATCH 3/9] Adding WEBSOCKET_HOST to settings. The setting WEBSOCKET_HOST enables using Websockets in cross domains. This is, the websocket domain (e.g. ws.myapp.com) is different from the site domain (e.g. www.myapp.com). However, it is mandatory to provide the Django setting SESSION_COOKIE_DOMAIN (e.g. SESSION_COOKIE_DOMAIN = '.myapp.com'). --- docs/installation.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/installation.rst b/docs/installation.rst index 677c885b..eaadbb50 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -142,6 +142,15 @@ channel. To restrict and control access, the ``WS4REDIS_ALLOWED_CHANNELS`` optio be set to a callback function anywhere inside your project. See the example and warnings in :ref:`SafetyConsiderations`. +Running Websockets in Cross Domains +----------------------------------- +In case you wish to listen to websocket connections in a cross domain (websocket domain name != site domain name), use the setting WEBSOCKET_HOST. However, it is mandatory to provide the Django setting SESSION_COOKIE_DOMAIN in order to tell Django to use the some cookie for both domains. If WEBSOCKET_HOST is not provided, it will be used the site domain (request.get_host()). + +.. code-block:: python + + WEBSOCKET_HOST = 'ws.myapp.com' # Change this according to your needs. + SESSION_COOKIE_DOMAIN = '.myapp.com' # Change this according to your needs. + Check your Installation ----------------------- With **Websockets for Redis** your Django application has immediate access to code written for From 33901118edac41bd12e2c9714eaaf88e88ab78fd Mon Sep 17 00:00:00 2001 From: yguarata Date: Thu, 14 Apr 2016 08:44:23 -0300 Subject: [PATCH 4/9] Adding cross domain support. Adding cross domain support. --- docs/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index d2220ae1..de957bf6 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -14,6 +14,8 @@ Release History 0.4.7 ----- +* Adding support to run websockets in cross domains (setting WEBSOCKET_HOST). + Improvements to the javascript API: * Performing reconnection attempts when the first connection (on instantiation) fails. From 154e241df122fc067fa36bc631cf5d19d8a6716d Mon Sep 17 00:00:00 2001 From: yguarata Date: Thu, 14 Apr 2016 08:46:32 -0300 Subject: [PATCH 5/9] Update changelog.rst --- docs/changelog.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index de957bf6..2a44a404 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -14,6 +14,9 @@ Release History 0.4.7 ----- + +Instalation settings: + * Adding support to run websockets in cross domains (setting WEBSOCKET_HOST). Improvements to the javascript API: From c5523bdeb0831395e2bfc35081357fe8fbb2022d Mon Sep 17 00:00:00 2001 From: yguarata Date: Thu, 14 Apr 2016 08:54:32 -0300 Subject: [PATCH 6/9] Update README.md with latest released version --- README.md | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7c11c747..2efe1080 100644 --- a/README.md +++ b/README.md @@ -15,15 +15,10 @@ intended to work under [uWSGI](http://projects.unbit.it/uwsgi/) and behind [NGiN or [Apache](http://httpd.apache.org/docs/2.4/mod/mod_proxy_wstunnel.html) version 2.4.5 or later. -New in 0.4.5 +New in 0.4.6 ------------ -* Created 1 requirements file under ``examples/chatserver/requirements.txt``. -* Renamed chatclient.py to test_chatclient.py - for django-nose testrunner. -* Migrated example project to django 1.7. -* Edited ``docs/testing.rst`` to show new changes for using example project. -* Added support for Python 3.3 and 3.4. -* Added support for Django-1.8 -* Removes the check for middleware by name. +* Added support for the Sec-WebSocket-Protocol header. Thanks to Erwin Junge. +* Fixed bug in unpacking binary websocket protocol. Features From b23d4c9e1c6ea4b590e8e18b3f9bcf2c869bd8fd Mon Sep 17 00:00:00 2001 From: yguarata Date: Thu, 13 Jul 2017 15:38:51 -0300 Subject: [PATCH 7/9] Fixing typo --- docs/changelog.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 2a44a404..76080756 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -14,8 +14,7 @@ Release History 0.4.7 ----- - -Instalation settings: +Installation settings: * Adding support to run websockets in cross domains (setting WEBSOCKET_HOST). From 5f56dc138fdb18074f2b736d55b767921fdc3c2d Mon Sep 17 00:00:00 2001 From: yguarata Date: Fri, 14 Jul 2017 09:06:27 -0300 Subject: [PATCH 8/9] Fixing changing log location and version. --- docs/changelog.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 76080756..63f4e64d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,6 +4,12 @@ Release History =============== +0.5.1 +----- +Installation settings: + +* Adding support to run websockets in cross domains (setting WEBSOCKET_HOST). + 0.5.0 ----- * Support for Django-1.11. @@ -14,10 +20,6 @@ Release History 0.4.7 ----- -Installation settings: - -* Adding support to run websockets in cross domains (setting WEBSOCKET_HOST). - Improvements to the javascript API: * Performing reconnection attempts when the first connection (on instantiation) fails. From 974aacb43465b776313b669e439749c5c07cfe2a Mon Sep 17 00:00:00 2001 From: yguarata Date: Mon, 17 Jul 2017 09:53:14 -0300 Subject: [PATCH 9/9] Update with last change log. --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2efe1080..b019179d 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,12 @@ intended to work under [uWSGI](http://projects.unbit.it/uwsgi/) and behind [NGiN or [Apache](http://httpd.apache.org/docs/2.4/mod/mod_proxy_wstunnel.html) version 2.4.5 or later. -New in 0.4.6 +New in 0.5.1 ------------ -* Added support for the Sec-WebSocket-Protocol header. Thanks to Erwin Junge. -* Fixed bug in unpacking binary websocket protocol. +Installation settings: + +* Adding support to run websockets in cross domains (setting WEBSOCKET_HOST). + Features