Merge branch '6.2.x'
This commit is contained in:
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1036,8 +1036,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
* @see #getDateHeader
|
||||
*/
|
||||
public void addHeader(String name, Object value) {
|
||||
if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name) &&
|
||||
!this.headers.containsKey(HttpHeaders.CONTENT_TYPE)) {
|
||||
if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name)) {
|
||||
setContentType(value.toString());
|
||||
}
|
||||
else if (HttpHeaders.ACCEPT_LANGUAGE.equalsIgnoreCase(name) &&
|
||||
|
||||
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -226,6 +226,15 @@ class MockHttpServletRequestTests {
|
||||
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
|
||||
void setContentTypeHeaderWithMoreComplexCharsetSyntax() {
|
||||
String contentType = "test/plain;charset=\"utf-8\";foo=\"charset=bar\";foocharset=bar;foo=bar";
|
||||
|
||||
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -471,12 +471,12 @@ class MockHttpServletRequestBuilderTests {
|
||||
assertThat(request.getContentType()).isEqualTo("yaml");
|
||||
}
|
||||
|
||||
@Test // SPR-11308
|
||||
@Test
|
||||
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);
|
||||
|
||||
assertThat(request.getContentType()).isEqualTo("text/html");
|
||||
assertThat(request.getContentType()).isEqualTo("text/plain");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1035,8 +1035,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
* @see #getDateHeader
|
||||
*/
|
||||
public void addHeader(String name, Object value) {
|
||||
if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name) &&
|
||||
!this.headers.containsKey(HttpHeaders.CONTENT_TYPE)) {
|
||||
if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name)) {
|
||||
setContentType(value.toString());
|
||||
}
|
||||
else if (HttpHeaders.ACCEPT_LANGUAGE.equalsIgnoreCase(name) &&
|
||||
|
||||
Reference in New Issue
Block a user