From 5db019638fc48a3a45d542b968d89345915008d1 Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Mon, 8 Jul 2024 14:35:16 +0200 Subject: [PATCH] Make Scala's StreamedResponse.headers case insensitively (cherry picked from commit d2a07f3ab1b84764eef43ba2b65ef707800c95e3) --- .../play/api/libs/ws/ahc/StreamedResponse.scala | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/play-ahc-ws-standalone/src/main/scala/play/api/libs/ws/ahc/StreamedResponse.scala b/play-ahc-ws-standalone/src/main/scala/play/api/libs/ws/ahc/StreamedResponse.scala index 04a8e812..d12ecd8f 100644 --- a/play-ahc-ws-standalone/src/main/scala/play/api/libs/ws/ahc/StreamedResponse.scala +++ b/play-ahc-ws-standalone/src/main/scala/play/api/libs/ws/ahc/StreamedResponse.scala @@ -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. * @@ -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 @@ -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. */