-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
annie-mac
committed
Nov 14, 2024
1 parent
6556422
commit e3939b3
Showing
7 changed files
with
183 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...src/main/java/com/azure/cosmos/implementation/http/Http2ResponseHeaderCleanerHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.cosmos.implementation.http; | ||
|
||
import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelInboundHandlerAdapter; | ||
import io.netty.handler.codec.http2.Http2Headers; | ||
import io.netty.handler.codec.http2.Http2HeadersFrame; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class Http2ResponseHeaderCleanerHandler extends ChannelInboundHandlerAdapter { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(Http2ResponseHeaderCleanerHandler.class); | ||
@Override | ||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { | ||
logger.info("In Http2HeaderCleanerHandler "); | ||
if (msg instanceof Http2HeadersFrame) { | ||
Http2HeadersFrame headersFrame = (Http2HeadersFrame) msg; | ||
Http2Headers headers = headersFrame.headers(); | ||
|
||
headers.forEach(entry -> { | ||
CharSequence key = entry.getKey(); | ||
CharSequence value = entry.getValue(); | ||
|
||
// Check for leading whitespace or other prohibited characters | ||
if (StringUtils.isNotEmpty(value) && (value.charAt(0) == ' ' || value.charAt(value.length() - 1) == ' ')) { | ||
// Clean up the header value by trimming or handling as needed | ||
logger.warn("There are extra white space for key {} with value {}", key, value); | ||
|
||
// TODO[Http2]: for now just trim the spaces, explore other options for example escape the whitespace | ||
headers.set(key, value.toString().trim()); | ||
} | ||
}); | ||
} | ||
|
||
// Pass the message to the next handler in the pipeline | ||
super.channelRead(ctx, msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"displayNames": { | ||
"-Pfast": "Fast", | ||
"-Pquery": "Query", | ||
"-Pcircuit-breaker-misc-gateway": "CircuitBreakerMiscGateway", | ||
"Session": "", | ||
"ubuntu": "", | ||
"@{ enableMultipleWriteLocations = $true; defaultConsistencyLevel = 'Session'; enableMultipleRegions = $true }": "" | ||
}, | ||
"include": [ | ||
{ | ||
"DESIRED_CONSISTENCIES": "[\"Session\"]", | ||
"ACCOUNT_CONSISTENCY": "Session", | ||
"ArmConfig": { | ||
"MultiMaster_MultiRegion": { | ||
"ArmTemplateParameters": "@{ enableMultipleWriteLocations = $true; defaultConsistencyLevel = 'Session'; enableMultipleRegions = $true }", | ||
"PREFERRED_LOCATIONS": "[\"East US 2\"]" | ||
} | ||
}, | ||
"PROTOCOLS": "[\"Tcp\"]", | ||
"ProfileFlag": [ "-Pquery", "-Pcircuit-breaker-misc-gateway", "-Pfast" ], | ||
"Agent": { | ||
"ubuntu": { "OSVmImage": "env:LINUXVMIMAGE", "Pool": "env:LINUXPOOL" } | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters