websockets-snap (empty) → 0.5.0.0
raw patch · 4 files changed
+98/−0 lines, 4 filesdep +basedep +snap-coredep +snap-serversetup-changed
Dependencies added: base, snap-core, snap-server, websockets
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- src/Network/WebSockets/Snap.hs +39/−0
- websockets-snap.cabal +27/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2011, Jasper Van der Jeugt <m@jaspervdj.be>++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Jasper Van der Jeugt <m@jaspervdj.be> nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Network/WebSockets/Snap.hs view
@@ -0,0 +1,39 @@+-- | Snap integration for the WebSockets library+module Network.WebSockets.Snap+ ( runWebSocketsSnap+ ) where++import qualified Network.WebSockets as WS+import qualified Snap.Core as Snap+import qualified Snap.Internal.Http.Types as Snap+import qualified Snap.Types.Headers as Headers++-- | The following function escapes from the current 'Snap.Snap' handler, and+-- continues processing the 'WS.WebSockets' action. The action to be executed+-- takes the 'WS.Request' as a parameter, because snap has already read this+-- from the socket.+runWebSocketsSnap :: WS.Protocol p+ => (WS.Request -> WS.WebSockets p ())+ -> Snap.Snap ()+runWebSocketsSnap = runWebSocketsSnapWith WS.defaultWebSocketsOptions++-- | Variant of 'runWebSocketsSnap' which allows custom options+runWebSocketsSnapWith :: WS.Protocol p+ => WS.WebSocketsOptions+ -> (WS.Request -> WS.WebSockets p ())+ -> Snap.Snap ()+runWebSocketsSnapWith options ws = do+ rq <- Snap.getRequest+ Snap.escapeHttp $ \tickle writeEnd ->+ let options' = options+ { WS.onPong = tickle 30 >> WS.onPong options+ }++ in WS.runWebSocketsWith options' (fromSnapRequest rq) ws writeEnd++-- | Convert a snap request to a websockets request+fromSnapRequest :: Snap.Request -> WS.RequestHttpPart+fromSnapRequest rq = WS.RequestHttpPart+ { WS.requestHttpPath = Snap.rqURI rq+ , WS.requestHttpHeaders = Headers.toList (Snap.rqHeaders rq)+ }
+ websockets-snap.cabal view
@@ -0,0 +1,27 @@+Name: websockets-snap+Version: 0.5.0.0+Synopsis: Snap integration for the websockets library+Description: Snap integration for the websockets library+License: BSD3+License-file: LICENSE+Author: Jasper Van der Jeugt <m@jaspervdj.be>+Maintainer: Jasper Van der Jeugt <m@jaspervdj.be>+Category: Network+Build-type: Simple+Cabal-version: >= 1.6++Library+ Hs-source-dirs: src++ Exposed-modules:+ Network.WebSockets.Snap++ Build-depends:+ base >= 4 && < 5,+ snap-core >= 0.7 && < 0.8,+ snap-server >= 0.7 && < 0.8,+ websockets >= 0.4 && < 0.6++Source-repository head+ Type: git+ Location: https://github.com/jaspervdj/websockets-snap