GH-1230 Ensure header names are case insensitive

Resolves #1230
This commit is contained in:
Oleg Zhurakousky
2025-04-02 13:56:27 +02:00
parent fff38bdda1
commit 8cd6f4f6c7
2 changed files with 15 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2023-2023 the original author or authors.
* Copyright 2023-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.
@@ -727,7 +727,7 @@ public class ServerlessHttpServletRequest implements HttpServletRequest {
}
public void setHeader(String name, @Nullable String value) {
this.headers.set(name, value);
this.headers.add(name, value);
}
public void addHeader(String name, @Nullable String value) {

View File

@@ -29,6 +29,7 @@ import org.springframework.cloud.function.test.app.Pet;
import org.springframework.cloud.function.test.app.PetStoreSpringAppConfig;
import org.springframework.cloud.function.test.app.PetStoreSpringAppConfig.AnotherFilter;
import org.springframework.cloud.function.test.app.PetStoreSpringAppConfig.SimpleFilter;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import static org.assertj.core.api.Assertions.assertThat;
@@ -56,6 +57,18 @@ public class RequestResponseTests {
public void after() {
this.mvc.stop();
}
@Test
public void validateCaseInsensitiveHeaders() throws Exception {
ServerlessHttpServletRequest request = new ServerlessHttpServletRequest(null, "GET", "/index");
request.setHeader("User-Agent", "iOS");
request.setHeader("uSer-Agent", "FOO");
request.setContentType("application/json");
request.setHeader("CoNteNt-tYpe", "text/plain");
assertThat(request.getHeader("content-TYPE")).isEqualTo("application/json");
assertThat(request.getHeader("user-agenT")).isEqualTo("iOS");
}
@Test
public void validateFreemarker() throws Exception {