From 820ca3ce6ae96c90412f1332bdc9b0471931c641 Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Mon, 8 Jul 2024 14:17:36 +0200 Subject: [PATCH] Add tests for StreamedResponse to make sure its header's map is case insensitively (cherry picked from commit f6bac8900a9cc4a07c32ce84d91c711ceb6d3df3) --- .../scala/play/api/libs/ws/ahc/AhcWSResponseSpec.scala | 8 ++++++++ .../test/scala/play/libs/ws/ahc/AhcWSResponseSpec.scala | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/play-ahc-ws-standalone/src/test/scala/play/api/libs/ws/ahc/AhcWSResponseSpec.scala b/play-ahc-ws-standalone/src/test/scala/play/api/libs/ws/ahc/AhcWSResponseSpec.scala index eeebc303..d44f16b1 100644 --- a/play-ahc-ws-standalone/src/test/scala/play/api/libs/ws/ahc/AhcWSResponseSpec.scala +++ b/play-ahc-ws-standalone/src/test/scala/play/api/libs/ws/ahc/AhcWSResponseSpec.scala @@ -128,6 +128,14 @@ class AhcWSResponseSpec extends Specification with DefaultBodyReadables with Def headers.contains("Bar") must beTrue } + "get headers map which retrieves headers case insensitively (for streamed responses)" in { + val srcHeaders = Map("Foo" -> Seq("a"), "foo" -> Seq("b"), "FOO" -> Seq("b"), "Bar" -> Seq("baz")) + val response = new StreamedResponse(null, 200, "", null, srcHeaders, null, true) + val headers = response.headers + headers("foo") must_== Seq("a", "b", "b") + headers("BAR") must_== Seq("baz") + } + "get a single header" in { val ahcResponse: AHCResponse = mock[AHCResponse] val ahcHeaders = new DefaultHttpHeaders(true) diff --git a/play-ahc-ws-standalone/src/test/scala/play/libs/ws/ahc/AhcWSResponseSpec.scala b/play-ahc-ws-standalone/src/test/scala/play/libs/ws/ahc/AhcWSResponseSpec.scala index 9a08b435..f0823d05 100644 --- a/play-ahc-ws-standalone/src/test/scala/play/libs/ws/ahc/AhcWSResponseSpec.scala +++ b/play-ahc-ws-standalone/src/test/scala/play/libs/ws/ahc/AhcWSResponseSpec.scala @@ -46,6 +46,14 @@ class AhcWSResponseSpec extends Specification with DefaultBodyReadables with Def headers.get("BAR").asScala must_== Seq("baz") } + "get headers map which retrieves headers case insensitively (for streamed responses)" in { + val srcHeaders = Map("Foo" -> Seq("a"), "foo" -> Seq("b"), "FOO" -> Seq("b"), "Bar" -> Seq("baz")) + val response = new StreamedResponse(null, 200, "", null, srcHeaders, null, true) + val headers = response.getHeaders + headers.get("foo").asScala must_== Seq("a", "b", "b") + headers.get("BAR").asScala must_== Seq("baz") + } + "get a single header" in { val srcResponse = mock[Response] val srcHeaders = new DefaultHttpHeaders()