Skip to content

Commit 81ea754

Browse files
committed
Merge branch '6.2.x'
2 parents 094e653 + fdab8fa commit 81ea754

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -1036,8 +1036,7 @@ private static String encodeCookies(Cookie... cookies) {
10361036
* @see #getDateHeader
10371037
*/
10381038
public void addHeader(String name, Object value) {
1039-
if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name) &&
1040-
!this.headers.containsKey(HttpHeaders.CONTENT_TYPE)) {
1039+
if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name)) {
10411040
setContentType(value.toString());
10421041
}
10431042
else if (HttpHeaders.ACCEPT_LANGUAGE.equalsIgnoreCase(name) &&

spring-test/src/test/java/org/springframework/mock/web/MockHttpServletRequestTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -226,6 +226,15 @@ void contentTypeHeaderUTF8() {
226226
assertThat(request.getCharacterEncoding()).isEqualTo("UTF-8");
227227
}
228228

229+
@Test
230+
void contentTypeMultipleCalls() {
231+
String contentType = "text/html";
232+
request.addHeader(HttpHeaders.CONTENT_TYPE, "text/plain");
233+
request.addHeader(HttpHeaders.CONTENT_TYPE, contentType);
234+
assertThat(request.getContentType()).isEqualTo(contentType);
235+
assertThat(request.getHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo(contentType);
236+
}
237+
229238
@Test // SPR-12677
230239
void setContentTypeHeaderWithMoreComplexCharsetSyntax() {
231240
String contentType = "test/plain;charset=\"utf-8\";foo=\"charset=bar\";foocharset=bar;foo=bar";

spring-test/src/test/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilderTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -471,12 +471,12 @@ void contentTypeViaHeaderWithInvalidValue() {
471471
assertThat(request.getContentType()).isEqualTo("yaml");
472472
}
473473

474-
@Test // SPR-11308
474+
@Test
475475
void contentTypeViaMultipleHeaderValues() {
476-
this.builder.header("Content-Type", MediaType.TEXT_HTML_VALUE, MediaType.ALL_VALUE);
476+
this.builder.header("Content-Type", MediaType.TEXT_HTML_VALUE, MediaType.TEXT_PLAIN_VALUE);
477477
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
478478

479-
assertThat(request.getContentType()).isEqualTo("text/html");
479+
assertThat(request.getContentType()).isEqualTo("text/plain");
480480
}
481481

482482
@Test

spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletRequest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -1035,8 +1035,7 @@ private static String encodeCookies(Cookie... cookies) {
10351035
* @see #getDateHeader
10361036
*/
10371037
public void addHeader(String name, Object value) {
1038-
if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name) &&
1039-
!this.headers.containsKey(HttpHeaders.CONTENT_TYPE)) {
1038+
if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name)) {
10401039
setContentType(value.toString());
10411040
}
10421041
else if (HttpHeaders.ACCEPT_LANGUAGE.equalsIgnoreCase(name) &&

0 commit comments

Comments
 (0)