Merge branch '6.2.x'

This commit is contained in:
Brian Clozel
2025-05-19 12:11:32 +02:00
4 changed files with 18 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -1036,8 +1036,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
* @see #getDateHeader * @see #getDateHeader
*/ */
public void addHeader(String name, Object value) { public void addHeader(String name, Object value) {
if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name) && if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name)) {
!this.headers.containsKey(HttpHeaders.CONTENT_TYPE)) {
setContentType(value.toString()); setContentType(value.toString());
} }
else if (HttpHeaders.ACCEPT_LANGUAGE.equalsIgnoreCase(name) && else if (HttpHeaders.ACCEPT_LANGUAGE.equalsIgnoreCase(name) &&

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -226,6 +226,15 @@ class MockHttpServletRequestTests {
assertThat(request.getCharacterEncoding()).isEqualTo("UTF-8"); assertThat(request.getCharacterEncoding()).isEqualTo("UTF-8");
} }
@Test
void contentTypeMultipleCalls() {
String contentType = "text/html";
request.addHeader(HttpHeaders.CONTENT_TYPE, "text/plain");
request.addHeader(HttpHeaders.CONTENT_TYPE, contentType);
assertThat(request.getContentType()).isEqualTo(contentType);
assertThat(request.getHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo(contentType);
}
@Test // SPR-12677 @Test // SPR-12677
void setContentTypeHeaderWithMoreComplexCharsetSyntax() { void setContentTypeHeaderWithMoreComplexCharsetSyntax() {
String contentType = "test/plain;charset=\"utf-8\";foo=\"charset=bar\";foocharset=bar;foo=bar"; String contentType = "test/plain;charset=\"utf-8\";foo=\"charset=bar\";foocharset=bar;foo=bar";

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -471,12 +471,12 @@ class MockHttpServletRequestBuilderTests {
assertThat(request.getContentType()).isEqualTo("yaml"); assertThat(request.getContentType()).isEqualTo("yaml");
} }
@Test // SPR-11308 @Test
void contentTypeViaMultipleHeaderValues() { void contentTypeViaMultipleHeaderValues() {
this.builder.header("Content-Type", MediaType.TEXT_HTML_VALUE, MediaType.ALL_VALUE); this.builder.header("Content-Type", MediaType.TEXT_HTML_VALUE, MediaType.TEXT_PLAIN_VALUE);
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext); MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
assertThat(request.getContentType()).isEqualTo("text/html"); assertThat(request.getContentType()).isEqualTo("text/plain");
} }
@Test @Test

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -1035,8 +1035,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
* @see #getDateHeader * @see #getDateHeader
*/ */
public void addHeader(String name, Object value) { public void addHeader(String name, Object value) {
if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name) && if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name)) {
!this.headers.containsKey(HttpHeaders.CONTENT_TYPE)) {
setContentType(value.toString()); setContentType(value.toString());
} }
else if (HttpHeaders.ACCEPT_LANGUAGE.equalsIgnoreCase(name) && else if (HttpHeaders.ACCEPT_LANGUAGE.equalsIgnoreCase(name) &&