XssProtectionMiddleware extends AbstractWebMiddleware<HttpRequest, NRES> { @Override public HttpResponse handle(HttpRequest httpRequest, MiddlewareChain<HttpRequest, NRES, ?, ?> chain) { HttpResponse response = castToHttpResponse(chain.next(httpRequest)); if (response != null) { header(response, "X-XSS-Protection", headerValue); } return response; } XssProtectionMiddleware();  XssProtectionMiddleware(boolean enable, OptionMap options); @Override HttpResponse handle(HttpRequest httpRequest, MiddlewareChain<HttpRequest, NRES, ?, ?> chain);  }
@Test void addXssBlockHeader() { XssProtectionMiddleware<HttpResponse> middleware = new XssProtectionMiddleware<>(); HttpRequest request = builder(new DefaultHttpRequest()) .build(); MiddlewareChain<HttpRequest, HttpResponse, ?, ?> chain = new DefaultMiddlewareChain<>(new AnyPredicate<>(), null, (Endpoint<HttpRequest, HttpResponse>) req -> builder(HttpResponse.of("hello")).build()); HttpResponse response = middleware.handle(request, chain); assertThat((String) HttpResponseUtils.getHeader(response, "X-XSS-Protection")) .isEqualTo("1; mode=block"); }