mapResponseHeaders
Signature
Description
Changes the list of response headers that was generated by the inner route.
The mapResponseHeaders
directive is used as a building block for Custom Directives to transform the list of
response headers that was generated by the inner route.
See Transforming the Response for similar directives.
Example
// adds all request headers to the response
val echoRequestHeaders = extract(_.request.headers).flatMap(respondWithHeaders)
val removeIdHeader = mapResponseHeaders(_.filterNot(_.lowercaseName == "id"))
val route =
removeIdHeader {
echoRequestHeaders {
complete("test")
}
}
// tests:
Get("/") ~> RawHeader("id", "12345") ~> RawHeader("id2", "67890") ~> route ~> check {
header("id") shouldEqual None
header("id2").get.value shouldEqual "67890"
}
Contents