respondWithHeaders

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

final HttpHeader gonzo = RawHeader.create("Funky-Muppet", "gonzo");
final HttpHeader akka = Origin.create(HttpOrigin.parse("http://akka.io"));

final Route route = path("foo", () ->
        respondWithHeaders(Arrays.asList(gonzo, akka), () ->
                complete("beep")
        )
);

testRoute(route).run(HttpRequest.GET("/foo"))
        .assertHeaderExists("Funky-Muppet", "gonzo")
        .assertHeaderExists("Origin", "http://akka.io")
        .assertEntity("beep");
The source code for this page can be found here.