From d3a955763521ed50678d0cfed2ca0161dd70760b Mon Sep 17 00:00:00 2001 From: Mohamed HABOU Date: Tue, 4 Apr 2017 17:25:36 +0100 Subject: [PATCH 1/2] add .toLowerCase() to req.get("Upgrade") and req.get("Connection") checks to support IE browsers before this change i got this error network error 12152 in IE browsers Hope this commit help someone --- .../com/pmeade/websocket/io/WebSocketServerInputStream.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/pmeade/websocket/io/WebSocketServerInputStream.java b/src/main/java/com/pmeade/websocket/io/WebSocketServerInputStream.java index 34faf26..1fcda98 100644 --- a/src/main/java/com/pmeade/websocket/io/WebSocketServerInputStream.java +++ b/src/main/java/com/pmeade/websocket/io/WebSocketServerInputStream.java @@ -467,8 +467,8 @@ private void shakeHands() throws IOException { handshakeComplete = checkStartsWith(requestLine, "GET /") && checkContains(requestLine, "HTTP/") && req.get("Host") != null - && checkContains(req.get("Upgrade"), "websocket") - && checkContains(req.get("Connection"), "Upgrade") + && checkContains(req.get("Upgrade").toLowerCase(), "websocket") + && checkContains(req.get("Connection").toLowerCase(), "Upgrade") && "13".equals(req.get("Sec-WebSocket-Version")) && req.get("Sec-WebSocket-Key") != null; String nonce = req.get("Sec-WebSocket-Key"); From fa24159de6472b0dafa233f726ee0b1e7ab68b9f Mon Sep 17 00:00:00 2001 From: Mohamed HABOU Date: Wed, 5 Apr 2017 11:53:34 +0100 Subject: [PATCH 2/2] Update WebSocketServerInputStream.java --- .../io/WebSocketServerInputStream.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/pmeade/websocket/io/WebSocketServerInputStream.java b/src/main/java/com/pmeade/websocket/io/WebSocketServerInputStream.java index 1fcda98..bead083 100644 --- a/src/main/java/com/pmeade/websocket/io/WebSocketServerInputStream.java +++ b/src/main/java/com/pmeade/websocket/io/WebSocketServerInputStream.java @@ -229,6 +229,20 @@ public static boolean checkContains(final String s1, final String s2) { } return s1.contains(s2); } + + /** + * Check if the first String contains() the second String and ignore case. This method + * returns false if the first string is null. + * @param s1 String to be checked if it contains + * @param s2 String to check for + * @return true, iff s1.contains(s2), otherwise false + */ + public static boolean checkContainsIgnoreCase(final String s1, final String s2) { + if (s1 == null) { + return false; + } + return s1.toLowerCase().contains(s2.toLowerCase()); + } /** * Check if the first String startsWith() the second String. This method @@ -467,8 +481,8 @@ private void shakeHands() throws IOException { handshakeComplete = checkStartsWith(requestLine, "GET /") && checkContains(requestLine, "HTTP/") && req.get("Host") != null - && checkContains(req.get("Upgrade").toLowerCase(), "websocket") - && checkContains(req.get("Connection").toLowerCase(), "Upgrade") + && checkContainsIgnoreCase(req.get("Upgrade"), "websocket") + && checkContainsIgnoreCase(req.get("Connection"), "Upgrade") && "13".equals(req.get("Sec-WebSocket-Version")) && req.get("Sec-WebSocket-Key") != null; String nonce = req.get("Sec-WebSocket-Key");