@@ -10,6 +10,7 @@ import java.util.function.Supplier
1010import java .util .zip .{GZIPInputStream , InflaterInputStream }
1111
1212import scala .collection .JavaConverters ._
13+ import scala .collection .immutable .ListMap
1314import scala .collection .mutable
1415import scala .concurrent .{ExecutionException , Future }
1516
@@ -241,7 +242,12 @@ case class Requester(verb: String,
241242 .map { case (k, v) => s """ $k=" $v" """ }
242243 .mkString(" ; " )
243244 ))
244- val allHeadersFlat = allHeaders.toList.flatMap { case (k, v) => Seq (k, v) }
245+ val lastOfEachHeader =
246+ allHeaders.foldLeft(ListMap .empty[String , (String , String )]) {
247+ case (acc, (k, v)) =>
248+ acc.updated(k.toLowerCase, k -> v)
249+ }
250+ val headersKeyValueAlternating = lastOfEachHeader.values.toList.flatMap { case (k, v) => Seq (k, v) }
245251
246252 val requestBodyInputStream = new PipedInputStream ()
247253 val requestBodyOutputStream = new PipedOutputStream (requestBodyInputStream)
@@ -255,7 +261,7 @@ case class Requester(verb: String,
255261 HttpRequest .newBuilder()
256262 .uri(url1.toURI)
257263 .timeout(Duration .ofMillis(readTimeout))
258- .headers(allHeadersFlat : _* )
264+ .headers(headersKeyValueAlternating : _* )
259265 .method(upperCaseVerb,
260266 (contentLengthHeader.headOption.map(_._2), compress) match {
261267 case (Some (" 0" ), _) => HttpRequest .BodyPublishers .noBody()
0 commit comments