Skip to content

Commit 3e48498

Browse files
committed
Change MIME mapping for .js from application/javascript to text/javascript
This application/javascript MIME type is deprecated. This commit therefore changes the MIME type mapping for *.js files from application/javascript to text/javascript in order to align with industry standards. Closes gh-33197
1 parent 59b9404 commit 3e48498

File tree

6 files changed

+12
-13
lines changed

6 files changed

+12
-13
lines changed

spring-test/src/test/java/org/springframework/test/context/aot/samples/web/WebSpringJupiterTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -64,7 +64,7 @@ void controller(@Value("${test.engine}") String testEngine) throws Exception {
6464
void resources() throws Exception {
6565
this.mockMvc.perform(get("/resources/Spring.js"))
6666
.andExpectAll(
67-
content().contentType("application/javascript"),
67+
content().contentType("text/javascript"),
6868
content().string(containsString("Spring={};"))
6969
);
7070
}

spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/context/WebAppResourceTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -69,7 +69,7 @@ public void resourceRequest() {
6969
testClient.get().uri("/resources/Spring.js")
7070
.exchange()
7171
.expectStatus().isOk()
72-
.expectHeader().contentType("application/javascript")
72+
.expectHeader().contentType("text/javascript")
7373
.expectBody(String.class).value(containsString("Spring={};"));
7474
}
7575

spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/WebAppResourceTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -67,7 +67,7 @@ public void setup() {
6767
@Test
6868
public void resourceRequest() throws Exception {
6969
this.mockMvc.perform(get("/resources/Spring.js"))
70-
.andExpect(content().contentType("application/javascript"))
70+
.andExpect(content().contentType("text/javascript"))
7171
.andExpect(content().string(containsString("Spring={};")));
7272
}
7373

spring-web/src/main/resources/org/springframework/http/mime.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ application/ipfix ipfix
146146
application/java-archive jar
147147
application/java-serialized-object ser
148148
application/java-vm class
149-
application/javascript js
149+
# application/javascript js
150150
# application/jose
151151
# application/jose+json
152152
# application/jrd+json
@@ -1686,7 +1686,7 @@ text/csv csv
16861686
# text/fwdred
16871687
# text/grammar-ref-list
16881688
text/html html htm
1689-
# text/javascript
1689+
text/javascript js
16901690
# text/jcr-cnd
16911691
# text/markdown
16921692
# text/mizar

spring-web/src/test/java/org/springframework/http/MediaTypeFactoryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class MediaTypeFactoryTests {
3030
@Test
3131
void getMediaType() {
3232
assertThat(MediaTypeFactory.getMediaType("file.xml")).contains(MediaType.APPLICATION_XML);
33-
assertThat(MediaTypeFactory.getMediaType("file.js")).contains(MediaType.parseMediaType("application/javascript"));
33+
assertThat(MediaTypeFactory.getMediaType("file.js")).contains(MediaType.parseMediaType("text/javascript"));
3434
assertThat(MediaTypeFactory.getMediaType("file.css")).contains(MediaType.parseMediaType("text/css"));
3535
assertThat(MediaTypeFactory.getMediaType("file.foobar")).isNotPresent();
3636
}

spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ void getResourceFromSubDirectory() throws Exception {
606606
setBestMachingPattern(exchange, "/**");
607607
this.handler.handle(exchange).block(TIMEOUT);
608608

609-
assertThat(exchange.getResponse().getHeaders().getContentType()).isEqualTo(MediaType.parseMediaType("application/javascript"));
609+
assertThat(exchange.getResponse().getHeaders().getContentType()).isEqualTo(MediaType.parseMediaType("text/javascript"));
610610
assertResponseBody(exchange, "function foo() { console.log(\"hello world\"); }");
611611
}
612612

@@ -619,12 +619,11 @@ void getResourceFromSubDirectoryOfAlternatePath() throws Exception {
619619
this.handler.handle(exchange).block(TIMEOUT);
620620

621621
HttpHeaders headers = exchange.getResponse().getHeaders();
622-
assertThat(headers.getContentType()).isEqualTo(MediaType.parseMediaType("application/javascript"));
622+
assertThat(headers.getContentType()).isEqualTo(MediaType.parseMediaType("text/javascript"));
623623
assertResponseBody(exchange, "function foo() { console.log(\"hello world\"); }");
624624
}
625625

626-
@Test
627-
// gh-27538, gh-27624
626+
@Test // gh-27538, gh-27624
628627
void filterNonExistingLocations() throws Exception {
629628
this.handler.afterPropertiesSet();
630629
ResourceWebHandler handler = new ResourceWebHandler();

0 commit comments

Comments
 (0)