diff --git a/IPython/frontend/html/notebook/base/handlers.py b/IPython/frontend/html/notebook/base/handlers.py
index 5a4dcd3..10b9202 100644
--- a/IPython/frontend/html/notebook/base/handlers.py
+++ b/IPython/frontend/html/notebook/base/handlers.py
@@ -214,15 +214,10 @@ class IPythonHandler(AuthenticatedHandler):
def ws_url(self):
"""websocket url matching the current request
- turns http[s]://host[:port] into
- ws[s]://host[:port]
+ By default, this is just `''`, indicating that it should match
+ the same host, protocol, port, etc.
"""
- proto = self.request.protocol.replace('http', 'ws')
- host = self.settings.get('websocket_host', '')
- # default to config value
- if host == '':
- host = self.request.host # get from request
- return "%s://%s" % (proto, host)
+ return self.settings.get('websocket_url', '')
@property
def mathjax_url(self):
diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py
index 7ba5210..f58e555 100644
--- a/IPython/frontend/html/notebook/notebookapp.py
+++ b/IPython/frontend/html/notebook/notebookapp.py
@@ -425,8 +425,12 @@ class NotebookApp(BaseIPythonApplication):
elif not new.endswith('/'):
self.base_kernel_url = new+'/'
- websocket_host = Unicode("", config=True,
- help="""The hostname for the websocket server."""
+ websocket_url = Unicode("", config=True,
+ help="""The base URL for the websocket server,
+ if it differs from the HTTP server (hint: it almost certainly doesn't).
+
+ Should be in the form of an HTTP origin: ws[s]://hostname[:port]
+ """
)
extra_static_paths = List(Unicode, config=True,
diff --git a/IPython/frontend/html/notebook/static/services/kernels/js/kernel.js b/IPython/frontend/html/notebook/static/services/kernels/js/kernel.js
index db9025f..5fb20e6 100644
--- a/IPython/frontend/html/notebook/static/services/kernels/js/kernel.js
+++ b/IPython/frontend/html/notebook/static/services/kernels/js/kernel.js
@@ -102,7 +102,11 @@ var IPython = (function (IPython) {
console.log("Kernel started: ", json.kernel_id);
this.running = true;
this.kernel_id = json.kernel_id;
- this.ws_url = json.ws_url;
+ var ws_url = json.ws_url;
+ if (ws_url.match(/wss?:\/\//) == null) {
+ ws_url = "ws" + location.origin.substr(4) + ws_url;
+ };
+ this.ws_url = ws_url;
this.kernel_url = this.base_url + "/" + this.kernel_id;
this.start_channels();
$([IPython.events]).trigger('status_started.Kernel', {kernel: this});