Skip to content

Commit

Permalink
Use correct content-type + utf8 for serving js+css
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- committed Feb 3, 2023
1 parent b8b6753 commit 2a21b85
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2a21b85

Please sign in to comment.