IPv6 and HyBi fixes.
- fix addrinfo to accept empty host as localhost - use correct host variable in addrinfo error message - accept HyBi 7, 8 and 9. No difference for now. - send close buffer correctly.
This commit is contained in:
parent
247b74950d
commit
7ae8711dc6
10
websocket.py
10
websocket.py
|
|
@ -148,9 +148,11 @@ Sec-WebSocket-Accept: %s\r
|
||||||
""" Resolve a host (and optional port) to an IPv4 or IPv6 address.
|
""" Resolve a host (and optional port) to an IPv4 or IPv6 address.
|
||||||
Returns: family, socktype, proto, canonname, sockaddr
|
Returns: family, socktype, proto, canonname, sockaddr
|
||||||
"""
|
"""
|
||||||
|
if not host:
|
||||||
|
host = 'localhost'
|
||||||
addrs = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM, socket.IPPROTO_TCP)
|
addrs = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM, socket.IPPROTO_TCP)
|
||||||
if not addrs:
|
if not addrs:
|
||||||
raise Exception("Could resolve host '%s'" % self.target_host)
|
raise Exception("Could resolve host '%s'" % host)
|
||||||
return addrs[0]
|
return addrs[0]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
@ -492,7 +494,7 @@ Sec-WebSocket-Accept: %s\r
|
||||||
if code != None:
|
if code != None:
|
||||||
msg = struct.pack(">H%ds" % (len(reason)), code)
|
msg = struct.pack(">H%ds" % (len(reason)), code)
|
||||||
|
|
||||||
buf = self.encode_hybi(msg, opcode=0x08, base64=False)
|
buf, h, t = self.encode_hybi(msg, opcode=0x08, base64=False)
|
||||||
self.client.send(buf)
|
self.client.send(buf)
|
||||||
|
|
||||||
elif self.version == "hixie-76":
|
elif self.version == "hixie-76":
|
||||||
|
|
@ -596,8 +598,8 @@ Sec-WebSocket-Accept: %s\r
|
||||||
if sys.hexversion < 0x2060000 or not numpy:
|
if sys.hexversion < 0x2060000 or not numpy:
|
||||||
raise self.EClose("Python >= 2.6 and numpy module is required for HyBi-07 or greater")
|
raise self.EClose("Python >= 2.6 and numpy module is required for HyBi-07 or greater")
|
||||||
|
|
||||||
if ver == '7':
|
if ver in ['7', '8', '9']:
|
||||||
self.version = "hybi-07"
|
self.version = "hybi-0" + ver
|
||||||
else:
|
else:
|
||||||
raise self.EClose('Unsupported protocol version %s' % ver)
|
raise self.EClose('Unsupported protocol version %s' % ver)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue