mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-06 01:21:38 -05:00
ein-jupyterhub: Fix websocket connects.
Made sure to add the right cookies to the websocket request. Websockets authenticate and everything is peachy now.
This commit is contained in:
parent
9a1579d5f6
commit
4f5f29d351
4 changed files with 22 additions and 14 deletions
|
@ -244,11 +244,12 @@ See: https://github.com/ipython/ipython/pull/3307"
|
|||
(format "http://%s" url-or-port)))
|
||||
(parsed-url (url-generic-parse-url url)))
|
||||
(if (ein:jupyterhub-url-p base-url)
|
||||
(format "%s://%s:%s/%s"
|
||||
(ein:trim-right (format "%s://%s:%s%s"
|
||||
protocol
|
||||
(url-host parsed-url)
|
||||
(url-port parsed-url)
|
||||
(url-filename parsed-url))
|
||||
"/")
|
||||
(format "%s://%s:%s" protocol (url-host parsed-url) (url-port parsed-url)))))))
|
||||
|
||||
|
||||
|
|
|
@ -585,10 +585,6 @@ of minor mode."
|
|||
"Query jupyter server for the list of available
|
||||
kernels. Results are stored in ein:available-kernelspec, hashed
|
||||
on server url/port."
|
||||
(ein:aif (ein:jupyterhub-url-p url-or-port)
|
||||
(let ((user-server-path (ein:$jh-user-server (ein:$jh-conn-user it))))
|
||||
(setf url-or-port (ein:url (ein:$jh-conn-url it)
|
||||
user-server-path))))
|
||||
(unless (gethash url-or-port ein:available-kernelspecs)
|
||||
(ein:query-singleton-ajax
|
||||
(list 'ein:qeury-kernelspecs url-or-port)
|
||||
|
|
|
@ -100,7 +100,11 @@ will be canceled \(see also `ein:query-singleton-ajax').
|
|||
(defun ein:jupyterhub-url-p (url)
|
||||
"Does URL reference a jupyterhub server? If so then return the
|
||||
connection structure representing the server."
|
||||
(gethash url *ein:jupyterhub-servers*))
|
||||
(let ((parsed (url-generic-parse-url url)))
|
||||
(or (gethash (format "http://%s:%s" (url-host parsed) (url-port parsed))
|
||||
*ein:jupyterhub-servers*)
|
||||
(gethash (format "https://%s:%s" (url-host parsed) (url-port parsed))
|
||||
*ein:jupyterhub-servers*))))
|
||||
|
||||
(defun ein:jupyterhub-correct-query-url-maybe (url-or-port)
|
||||
(let* ((parsed-url (url-generic-parse-url url-or-port))
|
||||
|
|
|
@ -88,16 +88,23 @@
|
|||
|
||||
;; This seems redundant, but websocket does not work otherwise.
|
||||
(defun ein:websocket--prepare-cookies (url)
|
||||
(let* ((parsed-url (url-generic-parse-url url))
|
||||
(let* ((jh-conn (ein:jupyterhub-url-p url))
|
||||
(parsed-url (url-generic-parse-url url))
|
||||
(host-port (if (url-port-if-non-default parsed-url)
|
||||
(format "%s:%s" (url-host parsed-url) (url-port parsed-url))
|
||||
(url-host parsed-url)))
|
||||
(securep (string-match "^wss://" url))
|
||||
(http-only-cookies (request-cookie-alist (concat "#HttpOnly_" (url-host (url-generic-parse-url url))) "/" securep)) ;; Current version of Jupyter store cookies as HttpOnly)
|
||||
(cookies (request-cookie-alist (url-host (url-generic-parse-url url)) "/" securep)))
|
||||
(when (or cookies http-only-cookies)
|
||||
(cookies (request-cookie-alist (url-host (url-generic-parse-url url)) "/" securep))
|
||||
(hub-cookies (request-cookie-alist (url-host (url-generic-parse-url url)) "/hub/" securep))
|
||||
(user-cookies (and jh-conn
|
||||
(request-cookie-alist
|
||||
(url-host (url-generic-parse-url url))
|
||||
(ein:$jh-user-server (ein:$jh-conn-user jh-conn))
|
||||
securep))))
|
||||
(when (or cookies http-only-cookies hub-cookies user-cookies)
|
||||
(ein:log 'debug "Storing cookies in prep for opening websocket (%s)" cookies)
|
||||
(dolist (c (append cookies http-only-cookies))
|
||||
(dolist (c (append cookies http-only-cookies hub-cookies user-cookies))
|
||||
(url-cookie-store (car c) (cdr c) nil host-port (car (url-path-and-query parsed-url)) securep)))))
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue