Skip to content

Commit e11700a

Browse files
Artur-deki
authored andcommitted
fix: Provide correct mime type for javascript and css
The correct mimetype for javascript is a requirement when loading javascript modules#
1 parent 0601ce7 commit e11700a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsServletContext.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@ public String getMimeType(String s) {
167167
if (mimeTypes == null) {
168168
mimeTypes = new MimetypesFileTypeMap();
169169
}
170-
170+
if (s.endsWith(".css")) {
171+
return "text/css";
172+
}
173+
if (s.endsWith(".js")) {
174+
return "application/javascript";
175+
}
171176
// TODO: The getContentType method of the MimetypesFileTypeMap returns application/octet-stream
172177
// instead of null when the type cannot be found. We should replace with an implementation that
173178
// loads the System mime types ($JAVA_HOME/lib/mime.types

aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/servlet/AwsServletContextTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ void getMimeType_mimeTypeOfCorrectFile_expectMime() {
6565
mimeType = ctx.getMimeType("file://" + tmpFilePath);
6666
assertEquals("text/plain", mimeType);
6767
}
68+
@Test
69+
void getMimeType_mimeTypeOfJavascript_expectApplicationJavascript() {
70+
String tmpFilePath = TMP_DIR + "some.js";
71+
AwsServletContext ctx = new AwsServletContext(null);
72+
String mimeType = ctx.getMimeType(tmpFilePath);
73+
assertEquals("application/javascript", mimeType);
74+
}
6875

6976
@Test
7077
void getMimeType_unknownExtension_expectAppOctetStream() {

0 commit comments

Comments
 (0)