mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-06 09:31:39 -05:00
Cookies for websocket authentication
Support recently added feature to websocket for including cookies in connection header. This allows us to connect to secured IPython 3.x (and 2.x I hope) servers.
This commit is contained in:
parent
aaee6d0348
commit
f3a7c61df3
1 changed files with 40 additions and 31 deletions
|
@ -27,9 +27,8 @@
|
||||||
|
|
||||||
(eval-when-compile (require 'cl))
|
(eval-when-compile (require 'cl))
|
||||||
(require 'websocket)
|
(require 'websocket)
|
||||||
|
|
||||||
(require 'ein-core)
|
(require 'ein-core)
|
||||||
|
(require 'url-cookie)
|
||||||
|
|
||||||
(defstruct ein:$websocket
|
(defstruct ein:$websocket
|
||||||
"A wrapper object of `websocket'.
|
"A wrapper object of `websocket'.
|
||||||
|
@ -55,12 +54,23 @@
|
||||||
onopen-args
|
onopen-args
|
||||||
closed-by-client)
|
closed-by-client)
|
||||||
|
|
||||||
|
(defun ein:websocket--prepare-cookies (url)
|
||||||
|
(let* ((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)))
|
||||||
|
(cookies (request-cookie-alist (url-host (url-generic-parse-url url)) "/")))
|
||||||
|
(when cookies
|
||||||
|
(dolist (c cookies)
|
||||||
|
(url-cookie-store (car c) (cdr c) nil host-port (car (url-path-and-query parsed-url)))))))
|
||||||
|
|
||||||
|
|
||||||
;; Issues opening websockets in IPython 2.0, think it is related to
|
;; Issues opening websockets in IPython 2.0, think it is related to
|
||||||
;; http://stackoverflow.com/questions/22202182/error-on-websocket-when-try-to-use-ipython-notebook-in-emacs
|
;; http://stackoverflow.com/questions/22202182/error-on-websocket-when-try-to-use-ipython-notebook-in-emacs
|
||||||
(defun ein:websocket (url &optional onmessage onclose onopen
|
(defun ein:websocket (url &optional onmessage onclose onopen
|
||||||
onmessage-args onclose-args onopen-args)
|
onmessage-args onclose-args onopen-args)
|
||||||
(let ((websocket (make-ein:$websocket
|
(ein:websocket--prepare-cookies url)
|
||||||
|
(let* ((websocket (make-ein:$websocket
|
||||||
:onmessage onmessage
|
:onmessage onmessage
|
||||||
:onclose onclose
|
:onclose onclose
|
||||||
:onopen onopen
|
:onopen onopen
|
||||||
|
@ -69,7 +79,6 @@
|
||||||
:onopen-args onopen-args))
|
:onopen-args onopen-args))
|
||||||
(ws (websocket-open
|
(ws (websocket-open
|
||||||
url
|
url
|
||||||
:cookies (ein:query-get-cookie (url-host (url-generic-parse-url url)) "/")
|
|
||||||
:on-open
|
:on-open
|
||||||
(lambda (ws)
|
(lambda (ws)
|
||||||
(let ((websocket (websocket-client-data ws)))
|
(let ((websocket (websocket-client-data ws)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue