Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore 0.8.0 behavior of header values overriding earlier ones for the same key #163

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading