From 9b5844abc93f0c1e9832bff4b7ead83915e88028 Mon Sep 17 00:00:00 2001 From: Matthew <37573096+BlueMatthew@users.noreply.github.com> Date: Thu, 16 Jun 2022 00:20:04 +0800 Subject: [PATCH 1/2] Use more standard name --- core/src/main/java/org/nanohttpd/protocols/http/NanoHTTPD.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/nanohttpd/protocols/http/NanoHTTPD.java b/core/src/main/java/org/nanohttpd/protocols/http/NanoHTTPD.java index 42c21514..90e1747a 100644 --- a/core/src/main/java/org/nanohttpd/protocols/http/NanoHTTPD.java +++ b/core/src/main/java/org/nanohttpd/protocols/http/NanoHTTPD.java @@ -478,7 +478,7 @@ protected static Map> decodeParameters(String queryString) public static String decodePercent(String str) { String decoded = null; try { - decoded = URLDecoder.decode(str, "UTF8"); + decoded = URLDecoder.decode(str, "UTF-8"); } catch (UnsupportedEncodingException ignored) { NanoHTTPD.LOG.log(Level.WARNING, "Encoding not supported, ignored", ignored); } From cf10fc86e792a6062837cb94eb686e23d4bf901f Mon Sep 17 00:00:00 2001 From: Matthew <37573096+BlueMatthew@users.noreply.github.com> Date: Thu, 16 Jun 2022 00:20:15 +0800 Subject: [PATCH 2/2] Set default charset as UTF-8 --- .../org/nanohttpd/protocols/http/content/ContentType.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/nanohttpd/protocols/http/content/ContentType.java b/core/src/main/java/org/nanohttpd/protocols/http/content/ContentType.java index bafe18ed..6efb7f73 100644 --- a/core/src/main/java/org/nanohttpd/protocols/http/content/ContentType.java +++ b/core/src/main/java/org/nanohttpd/protocols/http/content/ContentType.java @@ -38,7 +38,9 @@ public class ContentType { - private static final String ASCII_ENCODING = "US-ASCII"; + public static final String ASCII_ENCODING = "US-ASCII"; + + public static final String UTF8_ENCODING = "UTF-8"; private static final String MULTIPART_FORM_DATA_HEADER = "multipart/form-data"; @@ -69,7 +71,7 @@ public ContentType(String contentTypeHeader) { encoding = getDetailFromContentHeader(contentTypeHeader, CHARSET_PATTERN, null, 2); } else { contentType = ""; - encoding = "UTF-8"; + encoding = UTF8_ENCODING; } if (MULTIPART_FORM_DATA_HEADER.equalsIgnoreCase(contentType)) { boundary = getDetailFromContentHeader(contentTypeHeader, BOUNDARY_PATTERN, null, 2); @@ -92,7 +94,7 @@ public String getContentType() { } public String getEncoding() { - return encoding == null ? ASCII_ENCODING : encoding; + return encoding == null ? UTF8_ENCODING : encoding; } public String getBoundary() {