diff --git a/src/main/java/com/pmeade/websocket/io/WebSocketServerInputStream.java b/src/main/java/com/pmeade/websocket/io/WebSocketServerInputStream.java index 34faf26..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"), "websocket") - && checkContains(req.get("Connection"), "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");