Skip to content

Commit

Permalink
Quote cookie values
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
jodersky committed Dec 26, 2020
1 parent 70e8c48 commit dabd728
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion requests/src/requests/Requester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ case class Requester(verb: String,
connection.setRequestProperty(
"Cookie",
allCookies
.map{case (k, v) => k + "=" + v}
.map{case (k, v) => s"""$k="$v""""}
.mkString("; ")
)
}
Expand Down
8 changes: 8 additions & 0 deletions requests/test/src/requests/RequestTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ object RequestTests extends TestSuite{
val res2 = requests.get("https://httpbin.org/cookies").text().trim
assert(read(res2) == Obj("cookies" -> Obj()))
}
test("space"){
val s = requests.Session(cookieValues = Map("hello" -> "hello, world"))
val res1 = s.get("https://httpbin.org/cookies").text().trim
assert(read(res1) == Obj("cookies" -> Obj("hello" -> "hello, world")))
s.get("https://httpbin.org/cookies/set?freeform=test+test")
val res2 = s.get("https://httpbin.org/cookies").text().trim
assert(read(res2) == Obj("cookies" -> Obj("freeform" -> "test test", "hello" -> "hello, world")))
}
}
// Tests fail with 'Request to https://httpbin.org/absolute-redirect/4 failed with status code 404'
// test("redirects"){
Expand Down

0 comments on commit dabd728

Please sign in to comment.