-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eq instance of Connection #98
Comments
An |
This can't currently be done in a way that doesn't break backwards compatibility (i.e. introduce some custom monad to track the unique supply), because You could use some global-supply hack such as import Control.Concurrent.MVar
import Control.Concurrent.Supply (Supply)
import qualified Control.Concurrent.Supply as Supply
globalSupply :: MVar Supply
globalSupply = unsafePerformIO (Supply.newSupply >>= newMVar)
{-# NOINLINE globalSupply #-}
freshId :: IO Int
freshId = modifyMVar supply (\s ->
let (n, s') = Supply.freshId s
in pure (s', n))
data Connection = Connection
{ ...
, connectionId :: Int
} |
Alternatively, we can use the 4-tuple |
Just to be clear, does this mean that with the current state of |
The correct way to do this is to have the server pass the socket 4-tuples to the I don't really know what you mean by "trust the connections" though. Users should be identified by implementing proper authentication either over HTTPS or through WebSocket messages. |
I guess one pattern is to provide a nonce-style token to the user via http, and then identify the websocket connection based on what token they send over. |
Well, usually WebSocket apps are part of larger HTTP apps, which already have some sort of authentication system in place using cookies/headers. Since a WebSocket connection starts out like a normal HTTP request, a great pattern is to use your existing HTTP authentication layer to check the cookies before turning it into a WebSocket connection. This is possible with both the Snap and Yesod backends, and I've personally used this pattern successfully in the past. |
Dear Jasper,
I don't know if it is possible, but I think it would be really nice to have an Eq instance of Connection. That way I could have [Connection] and be able to move them to different lists based on some test. I'm working around it now by wrapping Connection and using Data.Supply to generate my own Eq instance. Just something to think about in your copious spare time ;-)
The text was updated successfully, but these errors were encountered: