mapResponseHeaders

mapResponseHeaders

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
final Route echoRequestHeaders = extract(
  ctx -> ctx.getRequest().getHeaders(),
  headers -> respondWithHeaders(headers, () -> complete("test"))
);

final Route route = mapResponseHeaders(headers -> {
  headers.removeIf(header -> header.lowercaseName().equals("id"));
  return headers;
}, () -> echoRequestHeaders);

// tests:
testRoute(route).run(HttpRequest.GET("/").addHeaders(
  Arrays.asList(RawHeader.create("id", "12345"),RawHeader.create("id2", "67890"))))
  .assertHeaderKindNotExists("id")
  .assertHeaderExists("id2", "67890");

Contents