diff --git a/README.md b/README.md index 7c11c747..b019179d 100644 --- a/README.md +++ b/README.md @@ -15,15 +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.5 +New in 0.5.1 ------------ -* 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. +Installation settings: + +* Adding support to run websockets in cross domains (setting WEBSOCKET_HOST). + Features diff --git a/docs/changelog.rst b/docs/changelog.rst index d2220ae1..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. 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 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 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,