From b0bae8dd3b3ae11a2bc84456bea42a0e5547e262 Mon Sep 17 00:00:00 2001 From: CT Tsai Date: Thu, 6 Aug 2020 14:59:00 +0800 Subject: [PATCH 1/2] Update HandshakeBuilder.java The "HOST" value in standard http header can not contain port --- .../com/neovisionaries/ws/client/HandshakeBuilder.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/neovisionaries/ws/client/HandshakeBuilder.java b/src/main/java/com/neovisionaries/ws/client/HandshakeBuilder.java index bbd6454b..dd6f05ea 100644 --- a/src/main/java/com/neovisionaries/ws/client/HandshakeBuilder.java +++ b/src/main/java/com/neovisionaries/ws/client/HandshakeBuilder.java @@ -44,15 +44,16 @@ class HandshakeBuilder public HandshakeBuilder(boolean secure, String userInfo, String host, String path) { - mSecure = secure; - mUserInfo = userInfo; - mHost = host; - mPath = path; // 'host' may contain ':{port}' at its end. // 'path' may contain '?{query}' at its end. mUri = URI.create(String.format("%s://%s%s", (secure ? "wss" : "ws"), host, path)); + + mSecure = secure; + mUserInfo = userInfo; + mHost = mUri.getHost(); + mPath = path; } From 921dd637d8d8eca99bac596b8ad69b535522a85c Mon Sep 17 00:00:00 2001 From: CT Tsai Date: Mon, 10 Aug 2020 13:41:37 +0800 Subject: [PATCH 2/2] Update HandshakeBuilder.java Refine code for https://github.com/TakahikoKawasaki/nv-websocket-client/pull/207 --- .../java/com/neovisionaries/ws/client/HandshakeBuilder.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/neovisionaries/ws/client/HandshakeBuilder.java b/src/main/java/com/neovisionaries/ws/client/HandshakeBuilder.java index dd6f05ea..c30b3756 100644 --- a/src/main/java/com/neovisionaries/ws/client/HandshakeBuilder.java +++ b/src/main/java/com/neovisionaries/ws/client/HandshakeBuilder.java @@ -50,9 +50,11 @@ public HandshakeBuilder(boolean secure, String userInfo, String host, String pat mUri = URI.create(String.format("%s://%s%s", (secure ? "wss" : "ws"), host, path)); + boolean hidePort = ((mSecure && mUri.getPort() == 443) || (!mSecure && mUri.getPort() == 80)); + mSecure = secure; mUserInfo = userInfo; - mHost = mUri.getHost(); + mHost = hidePort ? mUri.getHost() : mUri.getHost() + ":" + mUri.getPort(); mPath = path; }