FirebaseExtended / TubeSock

A WebSocket client library implemented in Java
79 stars 28 forks source link

Let HTTP header field names be case-insensitive (RFC 2616, 4.2) #13

Closed ocram closed 8 years ago

ocram commented 8 years ago

Please note that according to [RFC2616], all header field names in both HTTP requests and HTTP responses are case-insensitive.

-- RFC 6455, 4.1

and

Field names are case-insensitive.

-- RFC 2616, 4.2

The field values are already handled case-insensitively in WebSocketHandshake.java (also as per RFC 6455, 4.1). But the field keys still need to be fixed.

jongidal commented 8 years ago

I agree. I have worked well with Meteor websocket and TubeSock. But, the last TubeSock throw exception in handshaking.

I think the code to make header map of WebSocket.runReader() had better be changed like this:

       for (String line : handshakeLines)
      {
        String[] keyValue = line.split(": ", 2);
        headers.put(keyValue[0].toLowerCase(Locale.US), keyValue[1]);
      }

And, WebSocketHandShake.verifyServerHandshakeHeaders method had better be changed like this :

  public void verifyServerHandshakeHeaders(HashMap<String, String> headers)
  {
    if (!headers.get("upgrade").toLowerCase(Locale.US).equals("websocket"))
    {
      throw new WebSocketException("connection failed: missing header field in server handshake: Upgrade");
    }
    else if (!headers.get("connection").toLowerCase(Locale.US).equals("upgrade"))
    {
      throw new WebSocketException("connection failed: missing header field in server handshake: Connection");
    }
  }
rupalitomar5 commented 8 years ago

@gsoltis Can you merge this pull request?