diff options
author | Zdeněk Kořán <zkoran@gmail.com> | 2015-01-20 22:45:25 +0100 |
---|---|---|
committer | Zdeněk Kořán <zkoran@gmail.com> | 2015-01-20 22:45:25 +0100 |
commit | 6bafd7d28fc7947f263feb7134fc8a70084357c3 (patch) | |
tree | 40d34913ae2c7afff4f611043dcf70cb267654ca /src/main/java/com/android/volley/toolbox/HttpHeaderParser.java | |
parent | 1a39583f0ee06329f7918ed9a4c7d0e7cd342917 (diff) | |
download | volley-6bafd7d28fc7947f263feb7134fc8a70084357c3.tar.gz |
Change the default character encoding for JSON responses to UTF-8
According to RFC 7159 (Section 8.1), the default encoding of JSON should be UTF-8.
Using ISO-8859-1 as default causes incompatibility with some JSON APIs (e.g. wrong interpretation of internationalized strings).
Diffstat (limited to 'src/main/java/com/android/volley/toolbox/HttpHeaderParser.java')
-rw-r--r-- | src/main/java/com/android/volley/toolbox/HttpHeaderParser.java | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/main/java/com/android/volley/toolbox/HttpHeaderParser.java b/src/main/java/com/android/volley/toolbox/HttpHeaderParser.java index cb08432..601ac0f 100644 --- a/src/main/java/com/android/volley/toolbox/HttpHeaderParser.java +++ b/src/main/java/com/android/volley/toolbox/HttpHeaderParser.java @@ -115,10 +115,14 @@ public class HttpHeaderParser { } /** - * Returns the charset specified in the Content-Type of this header, - * or the HTTP default (ISO-8859-1) if none can be found. + * Retrieve a charset from headers + * + * @param headers An {@link java.util.Map} of headers + * @param defaultCharset Charset to return if none can be found + * @return Returns the charset specified in the Content-Type of this header, + * or the defaultCharset if none can be found. */ - public static String parseCharset(Map<String, String> headers) { + public static String parseCharset(Map<String, String> headers, String defaultCharset) { String contentType = headers.get(HTTP.CONTENT_TYPE); if (contentType != null) { String[] params = contentType.split(";"); @@ -132,6 +136,14 @@ public class HttpHeaderParser { } } - return HTTP.DEFAULT_CONTENT_CHARSET; + return defaultCharset; + } + + /** + * Returns the charset specified in the Content-Type of this header, + * or the HTTP default (ISO-8859-1) if none can be found. + */ + public static String parseCharset(Map<String, String> headers) { + return parseCharset(headers, HTTP.DEFAULT_CONTENT_CHARSET); } } |