1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-02-07 20:54:32 +00:00

Allow specifying whether to inhibit cookies on a per-URL basis

* url-http.el (url-http-create-request): Don't send cookies unless
requested.
(url-http-parse-headers): Don't store cookies unless requested.

* url.el (url-retrieve): Ditto

* url-queue.el (url-queue-retrieve): Take an optional
`inhibit-cookies' parameter.

* url-parse.el (url): Add the `use-cookies' slot to the URL struct
to be able to keep track of whether to do cookies or not on a
per-URL basis.
This commit is contained in:
Lars Ingebrigtsen 2012-02-08 01:04:42 +01:00
parent 7c4bbb6992
commit aacaa41911
5 changed files with 42 additions and 13 deletions

View File

@ -1,3 +1,18 @@
2012-02-08 Lars Ingebrigtsen <larsi@gnus.org>
* url-parse.el (url): Add the `use-cookies' slot to the URL struct
to be able to keep track of whether to do cookies or not on a
per-URL basis.
* url-queue.el (url-queue-retrieve): Take an optional
`inhibit-cookies' parameter.
* url.el (url-retrieve): Ditto
* url-http.el (url-http-create-request): Don't send cookies unless
requested.
(url-http-parse-headers): Don't store cookies unless requested.
2012-02-06 Lars Ingebrigtsen <larsi@gnus.org>
* url-cache.el (url-cache-prune-cache): New function.

View File

@ -320,8 +320,10 @@ request.")
;; Authorization
auth
;; Cookies
(url-cookie-generate-header-lines host real-fname
(equal "https" (url-type url-http-target-url)))
(when (url-use-cookies url-http-target-url)
(url-cookie-generate-header-lines
host real-fname
(equal "https" (url-type url-http-target-url))))
;; If-modified-since
(if (and (not no-cache)
(member url-http-method '("GET" nil)))
@ -498,7 +500,8 @@ should be shown to the user."
(file-name-handler-alist nil))
(setq class (/ url-http-response-status 100))
(url-http-debug "Parsed HTTP headers: class=%d status=%d" class url-http-response-status)
(url-http-handle-cookies)
(when (url-use-cookies url-http-target-url)
(url-http-handle-cookies))
(case class
;; Classes of response codes

View File

@ -35,7 +35,8 @@
(&optional type user password host portspec filename
target attributes fullness))
(:copier nil))
type user password host portspec filename target attributes fullness silent)
type user password host portspec filename target attributes fullness
silent (use-cookies t))
(defsubst url-port (urlobj)
(or (url-portspec urlobj)

View File

@ -50,10 +50,11 @@
(defstruct url-queue
url callback cbargs silentp
buffer start-time pre-triggered)
buffer start-time pre-triggered
inhibit-cookiesp)
;;;###autoload
(defun url-queue-retrieve (url callback &optional cbargs silent)
(defun url-queue-retrieve (url callback &optional cbargs silent inhibit-cookies)
"Retrieve URL asynchronously and call CALLBACK with CBARGS when finished.
Like `url-retrieve' (which see for details of the arguments), but
controls the level of parallelism via the
@ -63,7 +64,8 @@ controls the level of parallelism via the
(list (make-url-queue :url url
:callback callback
:cbargs cbargs
:silentp silent))))
:silentp silent
:inhibit-cookiesp inhibit-cookies))))
(url-queue-setup-runners))
;; To ensure asynch behaviour, we start the required number of queue
@ -131,7 +133,8 @@ controls the level of parallelism via the
(ignore-errors
(url-retrieve (url-queue-url job)
#'url-queue-callback-function (list job)
(url-queue-silentp job)))))
(url-queue-silentp job)
(url-queue-inhibit-cookiesp job)))))
(defun url-queue-prune-old-entries ()
(let (dead-jobs)

View File

@ -123,7 +123,7 @@ variable in the original buffer as a forwarding pointer.")
(autoload 'url-cache-prune-cache "url-cache")
;;;###autoload
(defun url-retrieve (url callback &optional cbargs silent)
(defun url-retrieve (url callback &optional cbargs silent inhibit-cookies)
"Retrieve URL asynchronously and call CALLBACK with CBARGS when finished.
URL is either a string or a parsed URL.
@ -147,7 +147,9 @@ The variables `url-request-data', `url-request-method' and
request; dynamic binding of other variables doesn't necessarily
take effect.
If SILENT, then don't message progress reports and the like."
If SILENT, then don't message progress reports and the like.
If INHIBIT-COOKIES, cookies will neither be stored nor sent to
the server."
;;; XXX: There is code in Emacs that does dynamic binding
;;; of the following variables around url-retrieve:
;;; url-standalone-mode, url-gateway-unplugged, w3-honor-stylesheets,
@ -158,14 +160,18 @@ If SILENT, then don't message progress reports and the like."
;;; webmail.el; the latter should be updated. Is
;;; url-cookie-multiple-line needed anymore? The other url-cookie-*
;;; are (for now) only used in synchronous retrievals.
(url-retrieve-internal url callback (cons nil cbargs) silent))
(url-retrieve-internal url callback (cons nil cbargs) silent
inhibit-cookies))
(defun url-retrieve-internal (url callback cbargs &optional silent)
(defun url-retrieve-internal (url callback cbargs &optional silent
inhibit-cookies)
"Internal function; external interface is `url-retrieve'.
CBARGS is what the callback will actually receive - the first item is
the list of events, as described in the docstring of `url-retrieve'.
If SILENT, don't message progress reports and the like."
If SILENT, don't message progress reports and the like.
If INHIBIT-COOKIES, cookies will neither be stored nor sent to
the server."
(url-do-setup)
(url-gc-dead-buffers)
(if (stringp url)
@ -177,6 +183,7 @@ If SILENT, don't message progress reports and the like."
(unless (url-type url)
(error "Bad url: %s" (url-recreate-url url)))
(setf (url-silent url) silent)
(setf (url-use-cookies url) (not inhibit-cookies))
;; Once in a while, remove old entries from the URL cache.
(when (zerop (% url-retrieve-number-of-calls 1000))
(url-cache-prune-cache))