DefaultCharsetMiddleware extends AbstractWebMiddleware<HttpRequest, NRES> { protected void addCharset(HttpResponse response, String charset) { String contentType = getHeader(response, "Content-Type"); if (isTextBasedContentType(contentType) && !isContainsCharset(contentType)) { HttpResponseUtils.charset(response, charset); } }  @Override HttpResponse handle(HttpRequest request, MiddlewareChain<HttpRequest, NRES, ?, ?> chain); void setDefaultCharset(String defaultCharset);  }
@Test void charset() { DefaultCharsetMiddleware middleware = new DefaultCharsetMiddleware(); HttpResponse response = builder(HttpResponse.of("aaa")) .set(HttpResponse::setHeaders, Headers.of("Content-Type", "text/html")) .build(); middleware.addCharset(response, "UTF-8"); String contentType = HttpResponseUtils.getHeader(response, "Content-Type"); assertThat(contentType) .isNotNull() .contains("UTF-8"); }