Skip to content

Commit 3bd12ef

Browse files
xinlian12annie-mac
andauthored
fixHttpHeadersCasingForFabric (#46736)
* useLowerCaseResponseHeaders --------- Co-authored-by: annie-mac <[email protected]>
1 parent 725ed7d commit 3bd12ef

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.cosmos.implementation.http;
5+
6+
import org.testng.annotations.Test;
7+
8+
import java.util.Map;
9+
10+
import static org.assertj.core.api.Assertions.assertThat;
11+
12+
public class HttpHeadersTests {
13+
14+
@Test(groups = "unit")
15+
public void caseInsensitiveToMap() {
16+
String headerName = "Etag";
17+
String headerValue = "123";
18+
19+
HttpHeaders headers = new HttpHeaders();
20+
headers.set(headerName, headerValue);
21+
22+
Map<String, String> lowerCaseMap = headers.toLowerCaseMap();
23+
assertThat(lowerCaseMap.get(headerName.toLowerCase())).isEqualTo(headerValue);
24+
25+
Map<String, String> caseSensitiveMap = headers.toMap();
26+
assertThat(caseSensitiveMap.get(headerName.toLowerCase())).isNull();
27+
assertThat(caseSensitiveMap.get(headerName)).isEqualTo(headerValue);
28+
}
29+
}

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#### Other Changes
1212
* Changed to use `PartitionKeyRangeCache` to get partition key range during startup and split handling. - [46700](https://github.com/Azure/azure-sdk-for-java/pull/46700)
13+
* Changed to use lower casing http header names for gateway response. - [46736](https://github.com/Azure/azure-sdk-for-java/pull/46736)
1314

1415
### 4.74.0 (2025-09-05)
1516

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxGatewayStoreModel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public StoreResponse unwrapToStoreResponse(
220220
return new StoreResponse(
221221
endpoint,
222222
statusCode,
223-
HttpUtils.unescape(headers.toMap()),
223+
HttpUtils.unescape(headers.toLowerCaseMap()),
224224
new ByteBufInputStream(retainedContent, true),
225225
size);
226226
} else {
@@ -230,7 +230,7 @@ public StoreResponse unwrapToStoreResponse(
230230
return new StoreResponse(
231231
endpoint,
232232
statusCode,
233-
HttpUtils.unescape(headers.toMap()),
233+
HttpUtils.unescape(headers.toLowerCaseMap()),
234234
null,
235235
0);
236236
}
@@ -583,7 +583,7 @@ private void validateOrThrow(RxDocumentServiceRequest request,
583583
String.format("%s, StatusCode: %s", cosmosError.getMessage(), statusCodeString),
584584
cosmosError.getPartitionedQueryExecutionInfo());
585585

586-
CosmosException dce = BridgeInternal.createCosmosException(request.requestContext.resourcePhysicalAddress, statusCode, cosmosError, headers.toMap());
586+
CosmosException dce = BridgeInternal.createCosmosException(request.requestContext.resourcePhysicalAddress, statusCode, cosmosError, headers.toLowerCaseMap());
587587
BridgeInternal.setRequestHeaders(dce, request.getHeaders());
588588
throw dce;
589589
}

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/http/HttpHeaders.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ public Map<String, String> toMap() {
117117
return result;
118118
}
119119

120+
/**
121+
* Get {@link Map} representation of the HttpHeaders collection with lower casing header name.
122+
*
123+
* @return the headers as map
124+
*/
125+
public Map<String, String> toLowerCaseMap() {
126+
final Map<String, String> result = new HashMap<>(headers.size());
127+
for (String headerName : headers.keySet()) {
128+
result.put(headerName, headers.get(headerName).value());
129+
}
130+
return result;
131+
}
132+
120133
@Override
121134
public Iterator<HttpHeader> iterator() {
122135
return headers.values().iterator();

0 commit comments

Comments
 (0)