mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-21 13:31:46 +00:00
Fix case sensitivity issue in ServletRequestHeadersAdapter
The RequestHeaderOverrideWrapper did not deduplicate in keySet() across underlying headers and overrides. A similar change in size() even if it was working correctly, to align with keySet and make it more efficient. Closes gh-36418
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2002-present 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.http.server;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ServletRequestHeadersAdapter}.
|
||||
*/
|
||||
public class ServletRequestHeadersAdapterTests {
|
||||
|
||||
private final MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
private final MultiValueMap<String, String> headersAdapter = ServletRequestHeadersAdapter.create(request);
|
||||
|
||||
|
||||
@Test // gh-36418
|
||||
void caseSensitiveOverride() {
|
||||
request.addHeader("foo", "value");
|
||||
headersAdapter.set("Foo", "override value");
|
||||
|
||||
assertThat(headersAdapter.size()).isEqualTo(1);
|
||||
assertThat(headersAdapter.keySet()).containsExactly("Foo");
|
||||
assertThat(headersAdapter.getFirst("foo")).isEqualTo("override value");
|
||||
assertThat(headersAdapter.get("foo")).containsExactly("override value");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user