websocket icon indicating copy to clipboard operation
websocket copied to clipboard

add .toLowerCase() to req.get("Upgrade") and req.get("Connection") c…

Open mhabou opened this issue 8 years ago • 2 comments

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

mhabou avatar Apr 04 '17 16:04 mhabou

Thank you for the PR @Dayssam.

Full disclosure: I don't have a Windows box, so I can't test this in IE myself. I rely upon you to know if it actually works or not. :-)

            && checkContains(req.get("Upgrade").toLowerCase(), "websocket")
            && checkContains(req.get("Connection").toLowerCase(), "Upgrade")

I do want to add this, but I'd rather do it like this:

            && checkContainsIgnoreCase(req.get("Upgrade"), "websocket")
            && checkContainsIgnoreCase(req.get("Connection"), "Upgrade")

req.get() in this context can return null if the request does not contain the specified header.

The checkContains() method checks and handles null values, so they aren't a problem in the existing code.

However, the code req.get("Upgrade").toLowerCase() will throw a NullPointerException if one tries to call toLowerCase() on a null return value from req.get().

This is why I'd think to make a checkContainsIgnoreCase which can guard against a null value and call toLowerCase() on the result if it exists.

I don't have time to do that right this second, but I'll take a look as soon as I can. If you want to amend this PR with that suggestion, that'd be awesome.

Thanks again @Dayssam!

blinkdog avatar Apr 04 '17 20:04 blinkdog

I created a new function checkContainsIgnoreCase to handle that

https://github.com/blinkdog/websocket/pull/5

Thank you very much

i have an other question

i'm using JAVA 6 , so i c'ant use java.nio.charset.StandardCharsets;

for the received message i got it char by char in http://www.websocket.org/echo.html

CONNECTED

SENT: Rock it with HTML5 WebSocket

RECEIVED: Data received: R

RECEIVED: Data received: o

RECEIVED: Data received: c

RECEIVED: Data received: k

RECEIVED: Data received:

RECEIVED: Data received: i

RECEIVED: Data received: t

RECEIVED: Data received:

RECEIVED: Data received: w

RECEIVED: Data received: i

RECEIVED: Data received: t

RECEIVED: Data received: h

RECEIVED: Data received:

RECEIVED: Data received: H

RECEIVED: Data received: T

RECEIVED: Data received: M

RECEIVED: Data received: L

RECEIVED: Data received: 5

RECEIVED: Data received:

RECEIVED: Data received: W

RECEIVED: Data received: e

RECEIVED: Data received: b

RECEIVED: Data received: S

RECEIVED: Data received: o

RECEIVED: Data received: c

RECEIVED: Data received: k

RECEIVED: Data received: e

RECEIVED: Data received: t ...

and in my example i got the first char of the received message WebSocket Rocks

Any idea ??

mhabou avatar Apr 05 '17 11:04 mhabou