Permalink
Browse files

As per the RFC; cookies should not automatically url-encode and url-d…

…ecode values. Fixes #82
  • Loading branch information...
1 parent 27299eb commit a704e8576cd30647e9b8f526fc0edeb2494e8a6b @dakrone committed Jul 9, 2012
Showing with 12 additions and 13 deletions.
  1. +2 −0 changelog.org
  2. +3 −6 src/clj_http/cookies.clj
  3. +7 −7 test/clj_http/test/cookies.clj
View
@@ -153,6 +153,8 @@
* Work log
Log of merges/issues/work that's gone in so I know what to put in
the changelog for the next release
+** 2012-07-09
+ - fix an issue where cookies were encoded and should not be
** 2012-06-15
- merged https://github.com/dakrone/clj-http/pull/80 to allow
specifying the keystore type
View
@@ -1,6 +1,5 @@
(ns clj-http.cookies
- (:use [clj-http.util :only [url-decode url-encode]]
- [clojure.string :only [blank? join lower-case]])
+ (:use [clojure.string :only [blank? join lower-case]])
(:import (org.apache.http.client.params ClientPNames CookiePolicy)
(org.apache.http.cookie ClientCookie CookieOrigin)
(org.apache.http.params BasicHttpParams)
@@ -36,16 +35,14 @@
:path (.getPath cookie)
:ports (when (.getPorts cookie) (seq (.getPorts cookie)))
:secure (.isSecure cookie)
- :value (try
- (url-decode (.getValue cookie))
- (catch Exception _ (.getValue cookie)))
+ :value (.getValue cookie)
:version (.getVersion cookie)})])
(defn to-basic-client-cookie
"Converts a cookie seq into a BasicClientCookie2."
[[cookie-name cookie-content]]
(doto (BasicClientCookie2. (name cookie-name)
- (url-encode (name (:value cookie-content))))
+ (name (:value cookie-content)))
(.setComment (:comment cookie-content))
(.setCommentURL (:comment-url cookie-content))
(.setDiscard (or (:discard cookie-content) true))
@@ -36,7 +36,7 @@
:value "example-value" :version 0}]))
(deftest test-decode-cookies-with-seq
- (let [cookies (decode-cookies [(str "ring-session=" (url-encode session))])]
+ (let [cookies (decode-cookies [(str "ring-session=" session)])]
(is (map? cookies))
(is (= 1 (count cookies)))
(let [cookie (get cookies "ring-session")]
@@ -48,7 +48,7 @@
(deftest test-decode-cookies-with-string
(let [cookies (decode-cookies
- (str "ring-session=" (url-encode session) ";Path=/"))]
+ (str "ring-session=" session ";Path=/"))]
(is (map? cookies))
(is (= 1 (count cookies)))
(let [cookie (get cookies "ring-session")]
@@ -65,7 +65,7 @@
{:cookies {"a" {:discard true :path "/"
:value "1" :version 0}} :headers {}}
{:headers {"set-cookie"
- (str "ring-session=" (url-encode session) ";Path=/")}}
+ (str "ring-session=" session ";Path=/")}}
{:cookies {"ring-session"
{:discard true :path "/"
:value session :version 0}} :headers {}}))
@@ -79,7 +79,7 @@
{:domain ".example.com" :path "/" :value "example-value"}]
"example-cookie=example-value"
["ring-session" {:value session}]
- (str "ring-session=" (url-encode session))))
+ (str "ring-session=" session)))
(deftest test-encode-cookies
(are [cookie expected]
@@ -96,7 +96,7 @@
:discard true :version 0}}
"example-cookie=example-value"
{"ring-session" {:value session}}
- (str "ring-session=" (url-encode session))))
+ (str "ring-session=" session)))
(deftest test-encode-cookie-header
(are [request expected]
@@ -115,7 +115,7 @@
:path "/"
:domain "example.com"}])]
(is (= "ring-session" (.getName cookie)))
- (is (= (url-encode session) (.getValue cookie)))
+ (is (= session (.getValue cookie)))
(is (= "/" (.getPath cookie)))
(is (= "example.com" (.getDomain cookie)))
(is (nil? (.getComment cookie)))
@@ -140,7 +140,7 @@
:secure true
:version 0}])]
(is (= "ring-session" (.getName cookie)))
- (is (= (url-encode session) (.getValue cookie)))
+ (is (= session (.getValue cookie)))
(is (= "/" (.getPath cookie)))
(is (= "example.com" (.getDomain cookie)))
(is (= "Example Comment" (.getComment cookie)))

0 comments on commit a704e85

Please sign in to comment.