Skip to content

Commit

Permalink
Can't override headers() in Scala 3 + stay compatible
Browse files Browse the repository at this point in the history
(cherry picked from commit 329a4bc)
  • Loading branch information
mkurz authored and mergify[bot] committed Jul 8, 2024
1 parent d43a472 commit 51b5bc5
Showing 1 changed file with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,44 @@ class StreamedResponse(
val status: Int,
val statusText: String,
val uri: java.net.URI,
headers: Map[String, scala.collection.Seq[String]],
publisher: Publisher[HttpResponseBodyPart],
val useLaxCookieEncoder: Boolean
) extends StandaloneWSResponse
with CookieBuilder {

def this(
client: StandaloneAhcWSClient,
status: Int,
statusText: String,
uri: java.net.URI,
headers: Map[String, scala.collection.Seq[String]],
publisher: Publisher[HttpResponseBodyPart],
useLaxCookieEncoder: Boolean
) = {
this(
client,
status,
statusText,
uri,
publisher,
useLaxCookieEncoder
)
origHeaders = headers
}

private var origHeaders: Map[String, scala.collection.Seq[String]] = Map.empty

/**
* Get the underlying response object.
*/
override def underlying[T]: T = publisher.asInstanceOf[T]

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

0 comments on commit 51b5bc5

Please sign in to comment.