From ef3a9b0acdc59d0d85de8f844499225ad225360c Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Sun, 29 Nov 2015 13:25:52 +0900 Subject: [PATCH] Relax the sanity check in HttpClientUpgradeHandler Motivation: HttpClientUpgradeHandler currently throws an IllegalStateException when the server sends a '101 Switching Protocols' response that has no 'Upgrade' header. Some servers do not send the 'Upgrade' header on a successful protocol upgrade and we could safely assume that the server accepted the requested protocol upgrade in such a case, looking from the response status code (101) Modifications: - Do not throw an IllegalStateException when the server responded 101 without a 'Upgrade' header - Note that we still check the equality of the 'Upgrade' header when it is present. Result: - Fixes #4523 - Better interoperability --- .../handler/codec/http/HttpClientUpgradeHandler.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientUpgradeHandler.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientUpgradeHandler.java index b7b3fda8e9..4e96a626bc 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientUpgradeHandler.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientUpgradeHandler.java @@ -216,14 +216,9 @@ public class HttpClientUpgradeHandler extends HttpObjectAggregator implements Ch } CharSequence upgradeHeader = response.headers().get(HttpHeaderNames.UPGRADE); - if (upgradeHeader == null) { + if (upgradeHeader != null && !AsciiString.contentEqualsIgnoreCase(upgradeCodec.protocol(), upgradeHeader)) { throw new IllegalStateException( - "Switching Protocols response missing UPGRADE header"); - } - if (!AsciiString.contentEqualsIgnoreCase(upgradeCodec.protocol(), upgradeHeader)) { - throw new IllegalStateException( - "Switching Protocols response with unexpected UPGRADE protocol: " - + upgradeHeader); + "Switching Protocols response with unexpected UPGRADE protocol: " + upgradeHeader); } // Upgrade to the new protocol.