@@ -1,6 +1,7 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2module Network.Wai.Handler.WebSockets
2module Network.Wai.Handler.WebSockets
3 ( intercept
3 ( intercept
6import Control.Monad.IO.Class (liftIO)
7import Control.Monad.IO.Class (liftIO)
@@ -19,9 +20,17 @@ intercept :: WS.Protocol p
19 => (WS.Request -> WS.WebSockets p ())
20 => (WS.Request -> WS.WebSockets p ())
20 -> Request
21 -> Request
21 -> Maybe (C.BufferedSource IO ByteString -> Socket -> C.ResourceT IO ())
22 -> Maybe (C.BufferedSource IO ByteString -> Socket -> C.ResourceT IO ())
23+intercept = interceptWith WS.defaultWebSocketsOptions
25+-- | Variation of 'intercept' which allows custom options.
26+interceptWith :: WS.Protocol p
27+ => WS.WebSocketsOptions
28+ -> (WS.Request -> WS.WebSockets p ())
30+ -> Maybe (C.BufferedSource IO ByteString -> Socket -> C.ResourceT IO ())
22−intercept app req = case lookup "upgrade" $ requestHeaders req of
31+interceptWith opts app req = case lookup "upgrade" $ requestHeaders req of
24− | S.map toLower s == "websocket" -> Just $ runWebSockets req' app
33+ | S.map toLower s == "websocket" -> Just $ runWebSockets opts req' app
25 | otherwise -> Nothing
34 | otherwise -> Nothing
26 _ -> Nothing
35 _ -> Nothing
@@ -29,13 +38,14 @@ intercept app req = case lookup "upgrade" $ requestHeaders req of
30-- | Internal function to run the WebSocket iteratee using the conduit library
39-- | Internal function to run the WebSocket iteratee using the conduit library
31runWebSockets :: WS.Protocol p
40runWebSockets :: WS.Protocol p
41+ => WS.WebSocketsOptions
32− => WS.RequestHttpPart
42+ -> WS.RequestHttpPart
33 -> (WS.Request -> WS.WebSockets p ())
43 -> (WS.Request -> WS.WebSockets p ())
34 -> C.BufferedSource IO ByteString
44 -> C.BufferedSource IO ByteString
36 -> C.ResourceT IO ()
46 -> C.ResourceT IO ()
37−runWebSockets req app source sock = do
47+runWebSockets opts req app source sock = do
38− step <- liftIO $ E.runIteratee $ WS.runWebSockets req app send
48+ step <- liftIO $ E.runIteratee $ WS.runWebSocketsWith opts req app send
39 source C.$$ C.sinkState (E.returnI step) push close
49 source C.$$ C.sinkState (E.returnI step) push close
41 send = WS.iterSocket sock
51 send = WS.iterSocket sock