MostAwesomeDude / txWS

Twisted WebSockets
Other
94 stars 29 forks source link

Problems with the "protocol" #16

Open d0n3val opened 11 years ago

d0n3val commented 11 years ago

Hi guys,

I needed to "hack" a line in txws.py to allow chrome to connect via websockets. Basically, this is the header Chrome is sending:

2013-08-27 00:36:58+0200 [WebSocketsProtocol (WebSocketProtocol),0,192.168.2.110] {'Origin': 'http://localhost:50000', 'Upgrade': 'websocket', 'Sec-WebSocket-Extensions': 'x-webkit-deflate-frame', 'Sec-WebSocket-Version': '13', 'Sec-WebSocket-Protocol': 'undefined', 'Host': '192.168.2.109:8081', 'Sec-WebSocket-Key': 'lhmkxWbtMFAN+Y37GCuDvA==', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36', 'Connection': 'Upgrade', 'Pragma': 'no-cache', 'Cache-Control': 'no-cache'}

Since 'Sec-WebSocket-Protocol' == 'undefined' this piece of code breaks:

    # Check whether a codec is needed. WS calls this a "protocol" for
    # reasons I cannot fathom.
    protocol = None
    if "WebSocket-Protocol" in self.headers:
        protocol = self.headers["WebSocket-Protocol"]
    elif "Sec-WebSocket-Protocol" in self.headers:
        protocol = self.headers["Sec-WebSocket-Protocol"]

    if protocol: #HERE I NEED TO ADD and protocol != "undefined":
        if protocol not in encoders or protocol not in decoders:
            log.msg("Couldn't handle WS protocol %s!" % protocol)
            return False
        self.codec = protocol

With this it seem to all work fine. I do not know the code, so let me know if I am doing something terrible here or I was lucky and found a bug ;)

Ric

MostAwesomeDude commented 11 years ago

This is a bug in Chrome.