ContentTypeOptionsMiddleware extends AbstractWebMiddleware<HttpRequest, NRES> { @Override public HttpResponse handle(HttpRequest httpRequest, MiddlewareChain<HttpRequest, NRES, ?, ?> next) { HttpResponse response = castToHttpResponse(next.next(httpRequest)); if (response != null) { header(response, "X-Content-Type-Options", contentTypeOptions); } return response; } ContentTypeOptionsMiddleware();  ContentTypeOptionsMiddleware(String contentTypeOptions); @Override HttpResponse handle(HttpRequest httpRequest, MiddlewareChain<HttpRequest, NRES, ?, ?> next);  }
@Test void testNoSniff() { MiddlewareChain<HttpRequest, HttpResponse, ?, ?> chain = new DefaultMiddlewareChain<>(new AnyPredicate<>(), null, (Endpoint<HttpRequest, HttpResponse>) req -> builder(HttpResponse.of("hello")) .set(HttpResponse::setHeaders, Headers.of("Content-Type", "text/html")) .build()); HttpResponse response = middleware.handle(request, chain); assertThat(response.getHeaders().get("X-Content-Type-Options")) .isEqualTo("nosniff"); }