From aacaa4191173ca6d1aea3fd4ebb01ea1d5e46e7b Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Wed, 8 Feb 2012 01:04:42 +0100 Subject: [PATCH] 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. --- lisp/url/ChangeLog | 15 +++++++++++++++ lisp/url/url-http.el | 9 ++++++--- lisp/url/url-parse.el | 3 ++- lisp/url/url-queue.el | 11 +++++++---- lisp/url/url.el | 17 ++++++++++++----- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog index f4cca618b49..179148a089d 100644 --- a/lisp/url/ChangeLog +++ b/lisp/url/ChangeLog @@ -1,3 +1,18 @@ +2012-02-08 Lars Ingebrigtsen + + * 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 * url-cache.el (url-cache-prune-cache): New function. diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el index b43ed7617ad..b2f93f093e6 100644 --- a/lisp/url/url-http.el +++ b/lisp/url/url-http.el @@ -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 diff --git a/lisp/url/url-parse.el b/lisp/url/url-parse.el index ef09622b0a9..b91c85c0c3d 100644 --- a/lisp/url/url-parse.el +++ b/lisp/url/url-parse.el @@ -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) diff --git a/lisp/url/url-queue.el b/lisp/url/url-queue.el index 976a26635cd..c9c6c4fe69e 100644 --- a/lisp/url/url-queue.el +++ b/lisp/url/url-queue.el @@ -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) diff --git a/lisp/url/url.el b/lisp/url/url.el index 03b66b15232..933bceb2e6f 100644 --- a/lisp/url/url.el +++ b/lisp/url/url.el @@ -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)) -- 2.39.2