- shakeHands :: Handle -> IO (Either String Request)
- getRequest :: Handle -> IO (Either String Request)
- putResponse :: Handle -> Request -> IO ()
- getFrame :: Handle -> IO ByteString
- putFrame :: Handle -> ByteString -> IO ()
- reqHost :: Request -> String
- reqPath :: Request -> String
- reqOrigin :: Request -> String
- reqLocation :: Request -> String
- data Request
Documentation
shakeHands :: Handle -> IO (Either String Request)Source
Accept and perform a handshake, no matter the request contents.
As long as the request is well-formed, the client will receive a response saying, essentially, "proceed". Use this function if you don't care who you're connected to, as long as that someone speaks the WebSocket protocol.
The function returns either a String in case of error, or a Request
on success. The Request
is returned purely for logging purposes, since the handshake has already been executed. Use this function immediately after establishing the WebSocket connection.
If you wish not to blindly accept requests but to filter them according to their contents, use the getRequest
and putResponse
functions.
getRequest :: Handle -> IO (Either String Request)Source
Reads the client's opening handshake and returns either a Request
based on its contents, or a String in case of an error.
putResponse :: Handle -> Request -> IO ()Source
Sends an accepting response based on the given Request
, thus accepting and ending the handshake.
getFrame :: Handle -> IO ByteStringSource
Receive a strict ByteString. Call this function only after having performed the handshake. This function will block until an entire frame is read. If the writing end of the handle is closed, the function returns an empty ByteString.
putFrame :: Handle -> ByteString -> IO ()Source
Send a strict ByteString. Call this function only after having performed the handshake.
reqLocation :: Request -> StringSource
Returns the requested location. Equal to (\r -> "ws://" ++ reqHost r ++ reqPath r)
.