Patch request to fix reading cookies with curl backend

Request, as of v0.2.0, does not properly read HttpOnly cookies as it thinks they
are comments. This change is to temporarily work around that issue.
This commit is contained in:
John Miller 2016-12-14 12:32:26 -06:00
parent 3fef68d053
commit a96fd5d0bd

View file

@ -29,6 +29,7 @@
(require 'websocket)
(require 'ein-core)
(require 'url-cookie)
(require 'request)
(defstruct ein:$websocket
"A wrapper object of `websocket'.
@ -54,6 +55,37 @@
onopen-args
closed-by-client)
;; Fix issues reading cookies in request when using curl backend
(defun fix-request-netscape-cookie-parse (next-method)
"Parse Netscape/Mozilla cookie format."
(goto-char (point-min))
(let ((tsv-re (concat "^\\="
(cl-loop repeat 6 concat "\\([^\t\n]+\\)\t")
"\\(.*\\)"))
cookies)
(forward-line 3) ;; Skip header (first three lines)
(while
(and
(cond
((re-search-forward "^\\=$" nil t))
((re-search-forward tsv-re)
(push (cl-loop for i from 1 to 7 collect (match-string i))
cookies)
t))
(= (forward-line 1) 0)
(not (= (point) (point-max)))))
(setq cookies (nreverse cookies))
(cl-loop for (domain flag path secure expiration name value) in cookies
collect (list domain
(equal flag "TRUE")
path
(equal secure "TRUE")
(string-to-number expiration)
name
value))))
(advice-add 'request--netscape-cookie-parse :around #'fix-request-netscape-cookie-parse)
;; This seems redundant, but websocket does not work otherwise.
(defun ein:websocket--prepare-cookies (url)
(let* ((parsed-url (url-generic-parse-url url))