diff --git a/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsHttpServletResponse.java b/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsHttpServletResponse.java index 63a2dca80..3f0c1678e 100644 --- a/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsHttpServletResponse.java +++ b/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsHttpServletResponse.java @@ -435,11 +435,15 @@ public void flushBuffer() throws IOException { // The content type is json but we have no encoding specified, according to the RFC (https://tools.ietf.org/html/rfc4627#section-3) // we should attempt to detect the encoding. However, since we are running in Lambda we shouldn't even consider // big endian systems and it's highly unlikely we'll have apps using UTF-16/32 we simply force UTF-8 - if (headers != null && headers.getFirst(HttpHeaders.CONTENT_TYPE) != null && - headers.getFirst(HttpHeaders.CONTENT_TYPE).toLowerCase(Locale.getDefault()).trim().equals(MediaType.APPLICATION_JSON) && - charset == null) { - charset = "UTF-8"; + if (charset == null && headers != null && headers.getFirst(HttpHeaders.CONTENT_TYPE) != null) { + String contentTypeLower = headers.getFirst(HttpHeaders.CONTENT_TYPE).toLowerCase(Locale.ENGLISH).trim(); + if (contentTypeLower.contains("charset=utf-8")) { + charset = "UTF-8"; + } else if (contentTypeLower.equals(MediaType.APPLICATION_JSON)) { + charset = "UTF-8"; + } } + // if at this point we are still null, we set the default if (charset == null) { diff --git a/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsServletContext.java b/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsServletContext.java index 6b027e37e..cc06f5ad9 100644 --- a/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsServletContext.java +++ b/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsServletContext.java @@ -136,11 +136,11 @@ public String getMimeType(String s) { if (mimeTypes == null) { mimeTypes = new MimetypesFileTypeMap(); } - if (s.endsWith(".js")) { - return "application/javascript"; - } if (s.endsWith(".css")) { - return "text/css"; + return "text/css; charset=utf-8"; + } + if (s.endsWith(".js")) { + return "application/javascript; charset=utf-8"; } // TODO: The getContentType method of the MimetypesFileTypeMap returns application/octet-stream // instead of null when the type cannot be found. We should replace with an implementation that