From baac352f74d7e5b2980ed9c1071515e6f85598eb Mon Sep 17 00:00:00 2001 From: Adrian Gonzalez Date: Wed, 9 Nov 2016 16:37:51 -0500 Subject: [PATCH] WebSocketClientHandshaker.rawPath(URI) should use the raw query Motivation: If the wsURL contains an encoded query, it will be decoded when generating the raw path. For example if the wsURL is http://test.org/path?a=1%3A5, the returned raw path would be /path?a=1:5 Modifications: Use wsURL.getRawQuery() rather than wsURL.getQuery() Result: rawPath will now return /path?a=1%3A5 --- .../http/websocketx/WebSocketClientHandshaker.java | 2 +- .../websocketx/WebSocketClientHandshakerTest.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java index 2f7c48e582..c1ff02e541 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java @@ -434,7 +434,7 @@ public abstract class WebSocketClientHandshaker { */ static String rawPath(URI wsURL) { String path = wsURL.getRawPath(); - String query = wsURL.getQuery(); + String query = wsURL.getRawQuery(); if (query != null && !query.isEmpty()) { path = path + '?' + query; } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshakerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshakerTest.java index b4e5e129d8..dc6c1a660a 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshakerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshakerTest.java @@ -52,6 +52,18 @@ public abstract class WebSocketClientHandshakerTest { } } + @Test + public void testRawPathWithQuery() { + URI uri = URI.create("ws://localhost:9999/path%20with%20ws?a=b%20c"); + WebSocketClientHandshaker handshaker = newHandshaker(uri); + FullHttpRequest request = handshaker.newHandshakeRequest(); + try { + assertEquals("/path%20with%20ws?a=b%20c", request.uri()); + } finally { + request.release(); + } + } + @Test(timeout = 3000) public void testHttpResponseAndFrameInSameBuffer() { testHttpResponseAndFrameInSameBuffer(false);