Skip to content

Commit

Permalink
Upcase cookie header name
Browse files Browse the repository at this point in the history
Since migrating to http4s we observed a flaw in cookie processing.
Previously, with akka the headers were uppercased. Http4s follows
RFC[1] related to header names more closely ignoring the case.
This had a result in missing cookie extractions in enrich that only
supports upper case Cookie header.

We are making enrich case-insensitive. Meanwhile, until the change
is migrated this is a workaround that will upcase cookie header.

1 -  https://www.rfc-editor.org/rfc/rfc7230#section-3.2
  • Loading branch information
peel committed Feb 20, 2024
1 parent f595862 commit ee6a019
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ class Service[F[_]: Sync](
request.headers.headers.flatMap { h =>
h.name match {
case ci"X-Forwarded-For" | ci"X-Real-Ip" | ci"Cookie" if spAnonymous.isDefined => None
case _ => Some(h.toString())
// FIXME: This is a temporary backport of old akka behaviour we will remove by
// adapting enrich to support a CIString header names as per RFC7230#Section-3.2
case ci"Cookie" => Some(s"Cookie: ${h.value}")
case _ => Some(h.toString())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,32 @@ class ServiceSpec extends Specification {
).asJava
}

"sink event with Cookie header upcased" in {
val ProbeService(service, good, bad) = probeService()

val req = Request[IO](
method = Method.POST,
headers = Headers(Header.Raw(CIString("cookie"), "name=value"))
)
val r = service
.cookie(
body = IO.pure(Some("b")),
path = "p",
request = req,
pixelExpected = false,
contentType = Some("image/gif")
)
.unsafeRunSync()

r.status mustEqual Status.Ok
good.storedRawEvents must have size 1
bad.storedRawEvents must have size 0

val e = emptyCollectorPayload
deserializer.deserialize(e, good.storedRawEvents.head)
e.headers.asScala must contain("Cookie: name=value")
}

"return necessary cache control headers and respond with pixel when pixelExpected is true" in {
val r = service
.cookie(
Expand Down

0 comments on commit ee6a019

Please sign in to comment.