Skip to content

Commit

Permalink
Merge pull request #146 from hmrc/BDOG-1512
Browse files Browse the repository at this point in the history
BDOG-1512 Header lookup defers to the `Seq#headOption` API
  • Loading branch information
tomwadeson authored Jul 1, 2022
2 parents 67c7f4a + 47743ad commit c4f2709
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ trait HttpResponse {
Source.single(ByteString(body))

def header(key: String): Option[String] =
headers.collectFirst { case (k, v :: _) if k.equalsIgnoreCase(key) => v }
headers
.collectFirst { case (k, values) if k.equalsIgnoreCase(key) => values }
.flatMap(_.headOption)

override def toString: String =
s"HttpResponse status=$status"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,22 @@ class HttpResponseSpec extends AnyWordSpec with Matchers {
}
}
}

"header" should {
"return the `headOption` value of the associated and case-insensitive header name" in {
val headers =
Map(
"Test-Header-1" -> Vector("v1", "v2"),
)

val response =
HttpResponse(
status = 200,
body = "",
headers = headers
)

response.header("test-header-1") shouldBe Some("v1")
}
}
}

0 comments on commit c4f2709

Please sign in to comment.