Skip to content

Commit

Permalink
Do not add Upgrade header if Connection header already present (t…
Browse files Browse the repository at this point in the history
…he caller manually manages connection state)
  • Loading branch information
ok2c committed Jan 7, 2025
1 parent 7ee083a commit 5ab09ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public void process(
final RequestConfig requestConfig = clientContext.getRequestConfigOrDefault();
if (requestConfig.isProtocolUpgradeEnabled()) {
final ProtocolVersion version = request.getVersion() != null ? request.getVersion() : clientContext.getProtocolVersion();
if (!request.containsHeader(HttpHeaders.UPGRADE) && version.getMajor() == 1 && version.getMinor() >= 1) {
if (!request.containsHeader(HttpHeaders.UPGRADE) &&
!request.containsHeader(HttpHeaders.CONNECTION) &&
version.getMajor() == 1 && version.getMinor() >= 1) {
if (LOG.isDebugEnabled()) {
LOG.debug("Connection is upgradable: protocol version = {}", version);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ void testDoUpgradeIfAlreadyTLS() throws Exception {
Assertions.assertFalse(get.containsHeader(HttpHeaders.UPGRADE));
}

@Test
void testDoUpgradeIfConnectionHeaderPresent() throws Exception {
final HttpRequest get = new BasicHttpRequest("GET", "/");
get.addHeader(HttpHeaders.CONNECTION, "keep-alive");
interceptor.process(get, null, context);
Assertions.assertFalse(get.containsHeader(HttpHeaders.UPGRADE));
}

@Test
void testDoUpgradeNonSafeMethodsOrTrace() throws Exception {
final HttpRequest post = new BasicHttpRequest("POST", "/");
Expand Down

0 comments on commit 5ab09ea

Please sign in to comment.