respondWithHeaders

respondWithHeaders

§Signature

§Description

Adds the given HTTP headers to all responses coming back from its inner route.

This directive transforms HttpResponse and ChunkedResponseStart messages coming back from its inner route by adding the given HttpHeader instances to the headers list.

See also respondWithHeader if you'd like to add just a single header.

§Example

  1. val route =
  2. path("foo") {
  3. respondWithHeaders(RawHeader("Funky-Muppet", "gonzo"), Origin(HttpOrigin("http://akka.io"))) {
  4. complete("beep")
  5. }
  6. }
  7.  
  8. // tests:
  9. Get("/foo") ~> route ~> check {
  10. header("Funky-Muppet") shouldEqual Some(RawHeader("Funky-Muppet", "gonzo"))
  11. header[Origin] shouldEqual Some(Origin(HttpOrigin("http://akka.io")))
  12. responseAs[String] shouldEqual "beep"
  13. }