1REQUIRE_MODULE LUA 2 3INCLUDE $TOP/test/config.htb 4 5SET 10K=$1K$1K$1K$1K$1K$1K$1K$1K$1K$1K 6SET 100K=$10K$10K$10K$10K$10K$10K$10K$10K$10K$10K 7 8BLOCK:LUA WebsocketAccept websocketKey : result 9 return crypto.base64.encode(crypto.evp.digest("sha1", websocketKey.."258EAFA5-E914-47DA-95CA-C5AB0DC85B11", true)) 10END 11 12CLIENT 13 _REQ $YOUR_HOST $YOUR_PORT 14 __GET / HTTP/1.1 15 __Host: $YOUR_HOST:$YOUR_PORT 16 __Upgrade: websocket 17 __Connection: Upgrade 18 __Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== 19 __Origin: http://$YOUR_HOST:$YOUR_PORT 20 __Sec-WebSocket-Protocol: chat, superchat 21 __Sec-WebSocket-Version: 13 22 __ 23 _EXPECT headers "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK\+xOo=" 24 _WAIT 25 _EXPECT . "BEGIN.*END" 26 _WS:RECV OP LEN 27 _ASSERT "$LEN == 65546" 28 _CLOSE 29END 30 31SERVER $YOUR_PORT 32 _RES 33 _MATCH headers "Sec-WebSocket-Key: (.*)" WebsocketKey 34 _WAIT 35 __HTTP/1.1 101 Switching Protocols 36 __Upgrade: websocket 37 __Connection: Upgrade 38 #__Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= 39 __Sec-WebSocket-Accept: $WebsocketAccept($WebsocketKey) 40 __Sec-WebSocket-Protocol: chat 41 __ 42 _FLUSH 43 _WS:SEND TEXT AUTO "BEGIN $10K$10K$10K$10K$10K$10K$1K$1K$1K$1K END" 44 _CLOSE 45END 46