mapResponseHeaders

Signature

def mapResponseHeaders(f: immutable.Seq[HttpHeader] ⇒ immutable.Seq[HttpHeader]): Directive0

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 Response Transforming Directives 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"
}
The source code for this page can be found here.