Skip to content

Commit 5d2ba4d

Browse files
committed
Merge pull request AsyncHttpClient#90 from gerdriesselmann/patch-1
Handle charsets that are quoted as if they were not (trim them).
2 parents 0de073a + 4cbe990 commit 5d2ba4d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/main/java/com/ning/http/util/AsyncHttpProviderUtils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,14 @@ public static String parseCharset(String contentType) {
429429
if (part.trim().startsWith("charset=")) {
430430
String[] val = part.split("=");
431431
if (val.length > 1) {
432-
return val[1].trim();
432+
String charset = val[1].trim();
433+
// Quite a lot of sites have charset="CHARSET",
434+
// e.g. charset="utf-8". Note the quotes. This is
435+
// not correct, but client should be able to handle
436+
// it (all browsers do, Apache HTTP Client and Grizzly
437+
// strip it by default)
438+
// This is a poor man's trim("\"").trim("'")
439+
return charset.replaceAll("\"", "").replaceAll("'", "")
433440
}
434441
}
435442
}

0 commit comments

Comments
 (0)