refactor websocket and add some test cases

refactor the code for websocket handshake, frame encode/decode, and add some test cases.