on master help sign in
Merge pull request #31 from jaspervdj/master
0b65c68Michael Snoyman
wai-websockets/Network/Wai/Handler/WebSockets.hs+15−5
@@ -1,6 +1,7 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2module Network.Wai.Handler.WebSockets
2module Network.Wai.Handler.WebSockets
3 ( intercept
3 ( intercept
4+ , interceptWith
4 ) where
5 ) where
5
6
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
24+
25+-- | Variation of 'intercept' which allows custom options.
26+interceptWith :: WS.Protocol p
27+ => WS.WebSocketsOptions
28+ -> (WS.Request -> WS.WebSockets p ())
29+ -> Request
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
23 Just s
32 Just s
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
27 where
36 where
@@ -29,13 +38,14 @@ intercept app req = case lookup "upgrade" $ requestHeaders req of
29
38
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
35 -> Socket
45 -> Socket
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
40 where
50 where
41 send = WS.iterSocket sock
51 send = WS.iterSocket sock
wai-websockets/wai-websockets.cabal+2−2
@@ -1,9 +1,9 @@
1Name: wai-websockets
1Name: wai-websockets
2−Version: 1.1.0
2+Version: 1.1.1
3Synopsis: Provide a bridge betweeen WAI and the websockets package.
3Synopsis: Provide a bridge betweeen WAI and the websockets package.
4License: BSD3
4License: BSD3
5License-file: LICENSE
5License-file: LICENSE
6−Author: Michael Snoyman
6+Author: Michael Snoyman, Jasper Van der Jeugt
7Maintainer: michael@snoyman.com
7Maintainer: michael@snoyman.com
8Homepage: http://github.com/yesodweb/wai
8Homepage: http://github.com/yesodweb/wai
9Category: Web, Yesod
9Category: Web, Yesod