On 4/6/2010 9:43 AM, Edi Weitz wrote: > But that's about different /attributes/ in the same cookie, that's not > exactly the same, is it? > > Yes, that's correct. Reading further I see:
4.3.3 Cookie Management If a user agent receives a Set-Cookie response header whose NAME is the same as a pre-existing cookie, and whose Domain and Path attribute values exactly (string) match those of a pre-existing cookie, the new cookie supersedes the old. I think this justifies :KEEP-LAST as the default behavior, if you interpret the first Set-Cookie header creating the cookie, and the second Set-Cookie header superseding the pre-existing cookie. I've attached a patch that introduces *remove-duplicate-cookies-p* as you mentioned in earlier email, with NIL as the default, so existing behavior is maintained. I haven't exported the symbol or added documentation yet, but wanted to run this by you first. I wrote a few unit tests (using the LIFT framework, http://common-lisp.net/project/lift/), are you interested in those? I'm honestly not sure what value they will have to anyone else, and I'm hesitant to add testing code to drakma proper if I'm the only one likely to run it (and I'm fairly unlikely to run it after my itch is scratched). If you'd like that, then I'll put together a separate patch with a drakma-tests.asd to sort out the dependencies. > _______________________________________________ > drakma-devel mailing list > drakma-devel@common-lisp.net > http://common-lisp.net/cgi-bin/mailman/listinfo/drakma-devel >
--- ../drakma-1.1.0/cookies.lisp 2009-12-01 17:06:56.000000000 -0500 +++ cookies.lisp 2010-04-06 10:53:24.000000000 -0400 @@ -258,6 +258,14 @@ (push (list (car name/value) (cdr name/value) parameters) result)))) (nreverse result))) +(defvar *remove-duplicate-cookies-p* nil + "Determines how duplicate cookies are handled. Valid values are: + * nil - duplicates will not be removed + * (T :KEEP-LAST) - for duplicates, only the last cookie value will be kept, + based on the order of the response header + * :KEEP-FIRST - for duplicates, only the first cookie value will be kept, + based on the order of the response header") + (defun get-cookies (headers uri) "Returns a list of COOKIE objects corresponding to the `Set-Cookie' header as found in HEADERS \(an alist as returned by @@ -281,7 +289,13 @@ (parse-cookie-date expires)) :domain domain :securep (not (not (parameter-present-p "secure" parameters))) - :http-only-p (not (not (parameter-present-p "HttpOnly" parameters)))))) + :http-only-p (not (not (parameter-present-p "HttpOnly" parameters)))) + into new-cookies + finally (return (ccase *remove-duplicate-cookies-p* + ((nil) new-cookies) + ((:keep-last t) (delete-duplicates new-cookies :test #'cookie=)) + (:keep-first (delete-duplicates new-cookies :test #'cookie= + :from-end T)))))) (defun update-cookies (new-cookies cookie-jar) "Updates the cookies in COOKIE-JAR by replacing those which are
_______________________________________________ drakma-devel mailing list drakma-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/drakma-devel