Skip to content

Commit

Permalink
Restore 0.8.0 behavior of header values overriding earlier ones for t…
Browse files Browse the repository at this point in the history
…he same key (#163)

Fixes #161
  • Loading branch information
nafg authored Jul 22, 2024
1 parent 6a32d03 commit fa71753
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions requests/src/requests/Requester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.util.function.Supplier
import java.util.zip.{GZIPInputStream, InflaterInputStream}

import scala.collection.JavaConverters._
import scala.collection.immutable.ListMap
import scala.collection.mutable
import scala.concurrent.{ExecutionException, Future}

Expand Down Expand Up @@ -241,7 +242,12 @@ case class Requester(verb: String,
.map { case (k, v) => s"""$k="$v"""" }
.mkString("; ")
))
val allHeadersFlat = allHeaders.toList.flatMap { case (k, v) => Seq(k, v) }
val lastOfEachHeader =
allHeaders.foldLeft(ListMap.empty[String, (String, String)]) {
case (acc, (k, v)) =>
acc.updated(k.toLowerCase, k -> v)
}
val headersKeyValueAlternating = lastOfEachHeader.values.toList.flatMap { case (k, v) => Seq(k, v) }

val requestBodyInputStream = new PipedInputStream()
val requestBodyOutputStream = new PipedOutputStream(requestBodyInputStream)
Expand All @@ -255,7 +261,7 @@ case class Requester(verb: String,
HttpRequest.newBuilder()
.uri(url1.toURI)
.timeout(Duration.ofMillis(readTimeout))
.headers(allHeadersFlat: _*)
.headers(headersKeyValueAlternating: _*)
.method(upperCaseVerb,
(contentLengthHeader.headOption.map(_._2), compress) match {
case (Some("0"), _) => HttpRequest.BodyPublishers.noBody()
Expand Down

0 comments on commit fa71753

Please sign in to comment.