From 36967884d352580e1f644bcc343b85bae1db1890 2014-07-22 21:43:40 From: MinRK Date: 2014-07-22 21:43:40 Subject: [PATCH] restore websocket_url configurable allows ws to be handled via separate proxies, as appears to be the case on OpenShift and some other hosting services. --- diff --git a/IPython/html/base/handlers.py b/IPython/html/base/handlers.py index 3bf2e2d..b52d5de 100644 --- a/IPython/html/base/handlers.py +++ b/IPython/html/base/handlers.py @@ -127,6 +127,10 @@ class IPythonHandler(AuthenticatedHandler): @property def base_url(self): return self.settings.get('base_url', '/') + + @property + def ws_url(self): + return self.settings.get('websocket_url', '') #--------------------------------------------------------------- # Manager objects @@ -215,6 +219,7 @@ class IPythonHandler(AuthenticatedHandler): def template_namespace(self): return dict( base_url=self.base_url, + ws_url=self.ws_url, logged_in=self.logged_in, login_available=self.login_available, static_url=self.static_url, diff --git a/IPython/html/notebookapp.py b/IPython/html/notebookapp.py index a18860a..013f14e 100644 --- a/IPython/html/notebookapp.py +++ b/IPython/html/notebookapp.py @@ -172,6 +172,7 @@ class NotebookWebApplication(web.Application): # IPython stuff nbextensions_path = ipython_app.nbextensions_path, + websocket_url=ipython_app.websocket_url, mathjax_url=ipython_app.mathjax_url, config=ipython_app.config, jinja2_env=env, @@ -512,6 +513,13 @@ class NotebookApp(BaseIPythonApplication): def _nbextensions_path_default(self): return [os.path.join(get_ipython_dir(), 'nbextensions')] + websocket_url = Unicode("", config=True, + help="""The base URL for websockets, + 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] + """ + ) mathjax_url = Unicode("", config=True, help="""The url for MathJax.js.""" ) diff --git a/IPython/html/static/notebook/js/main.js b/IPython/html/static/notebook/js/main.js index b36dcfc..d10787c 100644 --- a/IPython/html/static/notebook/js/main.js +++ b/IPython/html/static/notebook/js/main.js @@ -43,6 +43,7 @@ require([ var common_options = { base_url : utils.get_body_data("baseUrl"), + ws_url : IPython.utils.get_body_data("wsUrl"), notebook_path : utils.get_body_data("notebookPath"), notebook_name : utils.get_body_data('notebookName') }; diff --git a/IPython/html/static/services/kernels/js/kernel.js b/IPython/html/static/services/kernels/js/kernel.js index 6d41ca5..1506cd7 100644 --- a/IPython/html/static/services/kernels/js/kernel.js +++ b/IPython/html/static/services/kernels/js/kernel.js @@ -23,6 +23,11 @@ define([ this.stdin_channel = null; this.kernel_service_url = kernel_service_url; this.name = name; + this.ws_url = IPython.utils.get_body_data("wsUrl"); + if (!this.ws_url) { + // trailing 's' in https will become wss for secure web sockets + this.ws_url = location.protocol.replace('http', 'ws') + "//" + location.host; + } this.running = false; this.username = "username"; this.session_id = utils.uuid(); @@ -122,8 +127,6 @@ define([ console.log("Kernel started: ", json.id); this.running = true; this.kernel_id = json.id; - // trailing 's' in https will become wss for secure web sockets - this.ws_host = location.protocol.replace('http', 'ws') + "//" + location.host; this.kernel_url = utils.url_path_join(this.kernel_service_url, this.kernel_id); this.start_channels(); }; @@ -145,16 +148,16 @@ define([ Kernel.prototype.start_channels = function () { var that = this; this.stop_channels(); - var ws_host_url = this.ws_host + this.kernel_url; + var ws_host_url = this.ws_url + this.kernel_url; console.log("Starting WebSockets:", ws_host_url); this.shell_channel = new this.WebSocket( - this.ws_host + utils.url_join_encode(this.kernel_url, "shell") + this.ws_url + utils.url_join_encode(this.kernel_url, "shell") ); this.stdin_channel = new this.WebSocket( - this.ws_host + utils.url_join_encode(this.kernel_url, "stdin") + this.ws_url + utils.url_join_encode(this.kernel_url, "stdin") ); this.iopub_channel = new this.WebSocket( - this.ws_host + utils.url_join_encode(this.kernel_url, "iopub") + this.ws_url + utils.url_join_encode(this.kernel_url, "iopub") ); var already_called_onclose = false; // only alert once diff --git a/IPython/html/templates/notebook.html b/IPython/html/templates/notebook.html index 1193a8f..959621f 100644 --- a/IPython/html/templates/notebook.html +++ b/IPython/html/templates/notebook.html @@ -24,6 +24,7 @@ window.mathjax_url = "{{mathjax_url}}"; data-project="{{project}}" data-base-url="{{base_url}}" +data-ws-url="{{ws_url}}" data-notebook-name="{{notebook_name}}" data-notebook-path="{{notebook_path}}" class="notebook_app"