### Question:
HttpModifiedResponse extends StreamingHttpResponse { public String charset() { if (charset == null) { charset = "iso-8859-1"; String lookIn = contentTypeHeader(); if (lookIn == null) lookIn = getSampleContent("iso-8859-1"); String charsetEqTo = "charset="; int ix = lookIn.indexOf(charsetEqTo); if (ix != -1) { int endIx = lookIn.indexOf('"', ix); if (endIx == -1) endIx = lookIn.length(); charset = lookIn.substring(ix + charsetEqTo.length(), endIx).trim(); } if (charset.endsWith(";")) charset = charset.substring(0, charset.length() - 1); try { new String(new byte[]{}, charset); } catch (UnsupportedEncodingException e) { logger.debug("Defaulting to charset iso-8859-1", e); charset = "iso-8859-1"; } } return charset; } HttpModifiedResponse(final StreamingHttpResponse response, final boolean isSSL, String fileExtension, int responseCode);  HttpModifiedResponse(final HttpResponse response, final boolean isSSL, String fileExtension, int responseCode);  HttpModifiedResponse(HttpResponse response, boolean isSSL, String fileExtension); String charset();  }### Answer:
@Test public void testCharsetReturnsCharsetInMetaTag() { String s = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><meta http-equiv=\"zxz\"/></head>"; SimpleHttpResponse simpleHttpResponse = new SimpleHttpResponse(s); simpleHttpResponse.removeHeader("Content-Type"); assertEquals(null, simpleHttpResponse.contentTypeHeader()); HttpModifiedResponse resp = new HttpModifiedResponse(simpleHttpResponse, false, "htm"); assertEquals("utf-8", resp.charset()); }
@Test public void testCharsetReturnsCharsetInHeader() { String s = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=xx\" /><meta http-equiv=\"zxz\"/></head>"; SimpleHttpResponse simpleHttpResponse = new SimpleHttpResponse(s); simpleHttpResponse.removeHeader("Content-Type"); simpleHttpResponse.addHeader("Content-Type", "text/html; charset=utf-8"); assertEquals("text/html; charset=utf-8", simpleHttpResponse.contentTypeHeader()); HttpModifiedResponse resp = new HttpModifiedResponse(simpleHttpResponse, false, "htm"); assertEquals("utf-8", resp.charset()); }
@Test public void testCharsetReturnsISO88591IfNoCharset() { String s = "<html><head><meta http-equiv=\"zxz\"/></head>"; SimpleHttpResponse simpleHttpResponse = new SimpleHttpResponse(s); simpleHttpResponse.removeHeader("Content-Type"); assertEquals(null, simpleHttpResponse.contentTypeHeader()); HttpModifiedResponse resp = new HttpModifiedResponse(simpleHttpResponse, false, "htm"); assertEquals("iso-8859-1", resp.charset()); }
@Test public void testCharsetReturnsISO88591IfBadCharset() { String s = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=xx\" /><meta http-equiv=\"zxz\"/></head>"; SimpleHttpResponse simpleHttpResponse = new SimpleHttpResponse(s); simpleHttpResponse.removeHeader("Content-Type"); assertEquals(null, simpleHttpResponse.contentTypeHeader()); HttpModifiedResponse resp = new HttpModifiedResponse(simpleHttpResponse, false, "htm"); assertEquals("iso-8859-1", resp.charset()); }
@Test public void testCharsetReturnsCharsetWithSemiColonInHeader() { String s = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8;\" /><meta http-equiv=\"zxz\"/></head>"; SimpleHttpResponse simpleHttpResponse = new SimpleHttpResponse(s); simpleHttpResponse.removeHeader("Content-Type"); assertEquals(null, simpleHttpResponse.contentTypeHeader()); HttpModifiedResponse resp = new HttpModifiedResponse(simpleHttpResponse, false, "htm"); assertEquals("utf-8", resp.charset()); }