Skip to content

Commit

Permalink
Make Scala's StreamedResponse.headers case insensitively
Browse files Browse the repository at this point in the history
(cherry picked from commit d2a07f3)
  • Loading branch information
mkurz authored and mergify[bot] committed Jul 8, 2024
1 parent f74d044 commit 5db0196
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import play.api.libs.ws.StandaloneWSResponse
import play.api.libs.ws.WSCookie
import play.shaded.ahc.org.asynchttpclient.HttpResponseBodyPart

import scala.collection.immutable.TreeMap
import scala.collection.mutable

/**
* A streamed response containing a response header and a streamable body.
*
Expand Down Expand Up @@ -39,7 +42,7 @@ class StreamedResponse(
val status: Int,
val statusText: String,
val uri: java.net.URI,
val headers: Map[String, scala.collection.Seq[String]],
headers: Map[String, scala.collection.Seq[String]],
publisher: Publisher[HttpResponseBodyPart],
val useLaxCookieEncoder: Boolean
) extends StandaloneWSResponse
Expand All @@ -50,6 +53,17 @@ class StreamedResponse(
*/
override def underlying[T]: T = publisher.asInstanceOf[T]

override def headers(): Map[String, scala.collection.Seq[String]] = {
val mutableMap = mutable.TreeMap[String, scala.collection.Seq[String]]()(CaseInsensitiveOrdered)
headers.keys.foreach { name =>
mutableMap.updateWith(name) {
case Some(value) => Some(value ++ headers.getOrElse(name, Seq.empty))
case None => Some(headers.getOrElse(name, Seq.empty))
}
}
TreeMap[String, scala.collection.Seq[String]]()(CaseInsensitiveOrdered) ++ mutableMap
}

/**
* Get all the cookies.
*/
Expand Down

0 comments on commit 5db0196

Please sign in to comment.