Skip to content

Commit dabd728

Browse files
committed
Quote cookie values
According to [RFC2019](https://tools.ietf.org/html/rfc2109), this is required for values containing spaces, and should always be safe for non-space containing values. Note that most webservers are quite smart and lenient when parsing cookie headers. This change however is still useful for servers that are very strict (such as undertow).
1 parent 70e8c48 commit dabd728

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

requests/src/requests/Requester.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ case class Requester(verb: String,
247247
connection.setRequestProperty(
248248
"Cookie",
249249
allCookies
250-
.map{case (k, v) => k + "=" + v}
250+
.map{case (k, v) => s"""$k="$v""""}
251251
.mkString("; ")
252252
)
253253
}

requests/test/src/requests/RequestTests.scala

+8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ object RequestTests extends TestSuite{
110110
val res2 = requests.get("https://httpbin.org/cookies").text().trim
111111
assert(read(res2) == Obj("cookies" -> Obj()))
112112
}
113+
test("space"){
114+
val s = requests.Session(cookieValues = Map("hello" -> "hello, world"))
115+
val res1 = s.get("https://httpbin.org/cookies").text().trim
116+
assert(read(res1) == Obj("cookies" -> Obj("hello" -> "hello, world")))
117+
s.get("https://httpbin.org/cookies/set?freeform=test+test")
118+
val res2 = s.get("https://httpbin.org/cookies").text().trim
119+
assert(read(res2) == Obj("cookies" -> Obj("freeform" -> "test test", "hello" -> "hello, world")))
120+
}
113121
}
114122
// Tests fail with 'Request to https://httpbin.org/absolute-redirect/4 failed with status code 404'
115123
// test("redirects"){

0 commit comments

Comments
 (0)