diff --git a/AndroidAsync/src/com/koushikdutta/async/http/HttpUtil.java b/AndroidAsync/src/com/koushikdutta/async/http/HttpUtil.java index b7178ee6c..6a57ead1d 100644 --- a/AndroidAsync/src/com/koushikdutta/async/http/HttpUtil.java +++ b/AndroidAsync/src/com/koushikdutta/async/http/HttpUtil.java @@ -14,6 +14,8 @@ import com.koushikdutta.async.http.filter.GZIPInputFilter; import com.koushikdutta.async.http.filter.InflaterInputFilter; +import java.nio.charset.Charset; + public class HttpUtil { public static AsyncHttpRequestBody getBody(DataEmitter emitter, CompletedCallback reporter, Headers headers) { String contentType = headers.get("Content-Type"); @@ -59,7 +61,7 @@ public void run() { } } - public static DataEmitter getBodyDecoder(DataEmitter emitter, Protocol protocol, Headers headers, boolean server) { + public static DataEmitter getBodyDecoder(DataEmitter emitter, Protocol protocol, final Headers headers, boolean server) { long _contentLength; try { _contentLength = Long.parseLong(headers.get("Content-Length")); @@ -81,7 +83,19 @@ public static DataEmitter getBodyDecoder(DataEmitter emitter, Protocol protocol, emitter = ender; return emitter; } - ContentLengthFilter contentLengthWatcher = new ContentLengthFilter(contentLength); + String charset = null; + Multimap mm = Multimap.parseSemicolonDelimited(headers.get("Content-Type")); + String cs; + if (mm != null && null != (cs = mm.getString("charset")) && Charset.isSupported(cs)) { + charset = cs; + } + final String finalCharset = charset; + final ContentLengthFilter contentLengthWatcher = new ContentLengthFilter(contentLength){ + @Override + public String charset() { + return finalCharset; + } + }; contentLengthWatcher.setDataEmitter(emitter); emitter = contentLengthWatcher; } diff --git a/AndroidAsync/src/com/koushikdutta/async/parser/JSONObjectParser.java b/AndroidAsync/src/com/koushikdutta/async/parser/JSONObjectParser.java index e02db2c2e..d12d3f17e 100644 --- a/AndroidAsync/src/com/koushikdutta/async/parser/JSONObjectParser.java +++ b/AndroidAsync/src/com/koushikdutta/async/parser/JSONObjectParser.java @@ -5,6 +5,8 @@ import com.koushikdutta.async.callback.CompletedCallback; import com.koushikdutta.async.future.Future; import com.koushikdutta.async.future.TransformFuture; +import com.koushikdutta.async.util.Charsets; + import org.json.JSONObject; import java.lang.reflect.Type; @@ -15,7 +17,7 @@ public class JSONObjectParser implements AsyncParser { @Override public Future parse(DataEmitter emitter) { - return new StringParser().parse(emitter) + return new StringParser(emitter.charset() == null ? Charsets.UTF_8 : null ).parse(emitter) .then(new TransformFuture() { @Override protected void transform(String result) throws Exception {