switch default ws_url logic to js side

In some cases (proxies, #3305), the request object doesn't have the right information about the originating information.  This changes the default behavior, so that `ws_url` is generally empty by default, which the javascript takes to mean 'the same as http'.  This is simpler and should be more resilient than trying a guess on server-side.
MinRK 13 years ago
parent 70ca4f47e5
commit 2b45d245a4

@ -211,15 +211,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):

@ -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});

Loading…
Cancel
Save