Skip to content

Commit 8cd6f4f

Browse files
committed
GH-1230 Ensure header names are case insensitive
Resolves #1230
1 parent fff38bd commit 8cd6f4f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Diff for: spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/main/java/org/springframework/cloud/function/serverless/web/ServerlessHttpServletRequest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2023 the original author or authors.
2+
* Copyright 2023-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.
@@ -727,7 +727,7 @@ public Enumeration<String> getHeaderNames() {
727727
}
728728

729729
public void setHeader(String name, @Nullable String value) {
730-
this.headers.set(name, value);
730+
this.headers.add(name, value);
731731
}
732732

733733
public void addHeader(String name, @Nullable String value) {

Diff for: spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/test/java/org/springframework/cloud/function/serverless/web/RequestResponseTests.java

+13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.cloud.function.test.app.PetStoreSpringAppConfig;
3030
import org.springframework.cloud.function.test.app.PetStoreSpringAppConfig.AnotherFilter;
3131
import org.springframework.cloud.function.test.app.PetStoreSpringAppConfig.SimpleFilter;
32+
import org.springframework.http.HttpHeaders;
3233
import org.springframework.http.HttpStatus;
3334

3435
import static org.assertj.core.api.Assertions.assertThat;
@@ -56,6 +57,18 @@ public void before() {
5657
public void after() {
5758
this.mvc.stop();
5859
}
60+
61+
@Test
62+
public void validateCaseInsensitiveHeaders() throws Exception {
63+
ServerlessHttpServletRequest request = new ServerlessHttpServletRequest(null, "GET", "/index");
64+
request.setHeader("User-Agent", "iOS");
65+
request.setHeader("uSer-Agent", "FOO");
66+
request.setContentType("application/json");
67+
request.setHeader("CoNteNt-tYpe", "text/plain");
68+
69+
assertThat(request.getHeader("content-TYPE")).isEqualTo("application/json");
70+
assertThat(request.getHeader("user-agenT")).isEqualTo("iOS");
71+
}
5972

6073
@Test
6174
public void validateFreemarker() throws Exception {

0 commit comments

Comments
 (0)