### Question:
HttpClientDownloader extends AbstractDownloader { private String getHtmlCharset(String contentType, byte[] contentBytes) throws IOException { String charset = CharsetUtils.detectCharset(contentType, contentBytes); if (charset == null) { charset = Charset.defaultCharset().name(); LOGGER.warn("Charset autodetect failed, use {} as charset. Please specify charset in Site.setCharset()", Charset.defaultCharset()); } return charset; }  void setProxyProvider(ProxyProvider proxyProvider); void setHttpUriRequestConverter(HttpUriRequestConverter httpUriRequestConverter); @Override Page download(Request request, Task task); @Override void setThread(int threadNum);  }### Answer:
@Test public void testGetHtmlCharset() throws Exception { HttpServer server = httpServer(13423); server.get(by(uri("/header"))).response(header("Content-Type", "text/html; charset=gbk")); server.get(by(uri("/meta4"))).response(with(text("<html>\n" + " <head>\n" + " <meta charset='gbk'/>\n" + " </head>\n" + " <body></body>\n" + "</html>")), header("Content-Type", "text/html; charset=gbk")); server.get(by(uri("/meta5"))).response(with(text("<html>\n" + " <head>\n" + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=gbk\" />\n" + " </head>\n" + " <body></body>\n" + "</html>")), header("Content-Type", "text/html")); Runner.running(server, new Runnable() { @Override public void run() { String charset = getCharsetByUrl("http: assertEquals(charset, "gbk"); charset = getCharsetByUrl("http: assertEquals(charset, "gbk"); charset = getCharsetByUrl("http: assertEquals(charset, "gbk"); } private String getCharsetByUrl(String url) { Site site = Site.init(); CloseableHttpClient httpClient = new HttpClientGenerator().getClient(site); Request requestGBK = new Request(url); CloseableHttpResponse httpResponse = null; try { httpResponse = httpClient.execute(new HttpUriRequestConverter().convert(requestGBK, site, null).getHttpUriRequest()); } catch (IOException e) { e.printStackTrace(); } String charset = null; try { byte[] contentBytes = IOUtils.toByteArray(httpResponse.getEntity().getContent()); charset = CharsetUtils.detectCharset(httpResponse.getEntity().getContentType().getValue(), contentBytes); } catch (IOException e) { e.printStackTrace(); } return charset; } }); }