engine-io-snap (empty) → 1.0.0
raw patch · 5 files changed
+104/−0 lines, 5 filesdep +attoparsec-enumeratordep +basedep +bytestringsetup-changed
Dependencies added: attoparsec-enumerator, base, bytestring, containers, engine-io, snap-core, unordered-containers, websockets, websockets-snap
Files
- Changelog.md +3/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- engine-io-snap.cabal +31/−0
- src/Network/EngineIO/Snap.hs +38/−0
+ Changelog.md view
@@ -0,0 +1,3 @@+## 1.0.0++* Initial release.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2014, Oliver Charles++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 Oliver Charles 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
+ engine-io-snap.cabal view
@@ -0,0 +1,31 @@+name: engine-io-snap+version: 1.0.0+license: BSD3+license-file: LICENSE+author: Oliver Charles+maintainer: ollie@ocharles.org.uk+build-type: Simple+cabal-version: >=1.10+extra-source-files: Changelog.md+description:+ This package provides an @engine-io@ @ServerAPI@ that is compatible with+ <http://snapframework.com Snap>.++library+ exposed-modules:+ Network.EngineIO.Snap++ build-depends:+ attoparsec-enumerator >= 0.3 && <0.4,+ base >=4.6 && <4.8,+ bytestring >= 0.9 && <0.11,+ containers >=0.5 && <0.6,+ engine-io >= 1.0 && <1.1,+ snap-core >= 0.9 && <0.10,+ unordered-containers >= 0.2 && <0.3,+ websockets >=0.8 && <0.9,+ websockets-snap >= 0.8 && <0.9++ hs-source-dirs: src+ default-language: Haskell2010+ ghc-options: -Wall -O2
+ src/Network/EngineIO/Snap.hs view
@@ -0,0 +1,38 @@+{-# LANGUAGE OverloadedStrings #-}+module Network.EngineIO.Snap (snapAPI) where++import Control.Applicative++import qualified Data.Attoparsec.Enumerator as Attoparsec+import qualified Data.ByteString.Builder as Builder+import qualified Data.HashMap.Strict as HashMap+import qualified Data.Map.Lazy as LMap+import qualified Network.EngineIO as EIO+import qualified Network.WebSockets.Snap as Snap+import qualified Snap.Core as Snap++--------------------------------------------------------------------------------+-- | A drop in 'EIO.ServerAPI' that works in any Snap monad - including both+-- @Handler@ and @Snap@.+snapAPI :: Snap.MonadSnap m => EIO.ServerAPI m+snapAPI = EIO.ServerAPI+ { EIO.srvWriteBuilder = Snap.writeLBS . Builder.toLazyByteString++ , EIO.srvSetContentType = Snap.modifyResponse . Snap.setContentType++ , EIO.srvGetQueryParams =+ LMap.foldlWithKey' (\m k v -> HashMap.insert k v m) HashMap.empty+ <$> Snap.getQueryParams++ , EIO.srvParseRequestBody = Snap.runRequestBody . Attoparsec.iterParser++ , EIO.srvGetRequestMethod = do+ m <- Snap.getsRequest Snap.rqMethod+ return $ case m of+ Snap.GET -> "GET"+ Snap.POST -> "POST"++ , EIO.srvRunWebSocket = Snap.runWebSocketsSnap++ , EIO.srvSetResponseCode = Snap.modifyResponse . Snap.setResponseCode+ }