Implement closing handshake for WebSocket protocol

This patch adds frame header construction and client-to-server
payload masking support to the WebSocket implementation which
makes it possible to send messages to the server.
Implement closing handshake to properly close the connection
with the server and add more tests to increase the test coverage.
Fix warnings and typos in various places