respondWithHeaders
Adds the given HTTP headers to all responses coming back from its inner route.
Signature
def respondWithHeaders(responseHeaders: HttpHeader*): Directive0
def respondWithHeaders(responseHeaders: List[HttpHeader]): Directive0
Description
This directive transforms HttpResponse and ChunkedResponseStart messages coming back from its inner route by
adding the given HttpHeader instances to the headers list.
If you’d like to add just a single header you can use the respondWithHeader directive instead.
Example
val route =
path("foo") {
respondWithHeaders(RawHeader("Funky-Muppet", "gonzo"), Origin(Seq(HttpOrigin("http://spray.io")))) {
complete("beep")
}
}
Get("/foo") ~> route ~> check {
header("Funky-Muppet") === Some(RawHeader("Funky-Muppet", "gonzo"))
header[Origin] === Some(Origin(Seq(HttpOrigin("http://spray.io"))))
responseAs[String] === "beep"
}