packages feed

wai-eventsource 1.1.0.1 → 3.0.0

raw patch · 4 files changed

Files

LICENSE view
@@ -1,25 +1,20 @@-The following license covers this documentation, and the source code, except-where otherwise indicated.--Copyright 2012, Chris Smith, Mathias Biilmann Christensen. All rights reserved.--Redistribution and use in source and binary forms, with or without-modification, are permitted provided that the following conditions are met:+Copyright (c) 2012 Michael Snoyman, http://www.yesodweb.com/ -* Redistributions of source code must retain the above copyright notice, this-  list of conditions and the following disclaimer.+Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions: -* 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.+The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "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 HOLDERS 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.+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
− src/Network/Wai/EventSource.hs
@@ -1,75 +0,0 @@-{-# LANGUAGE OverloadedStrings #-}-module Network.Wai.EventSource (-    ServerEvent(..),-    eventSourceApp,-    eventSourceAppChan,-    eventSourceAppSource,-    eventSourceAppIO-    ) where--import           Blaze.ByteString.Builder (Builder)-import           Control.Concurrent.Chan (Chan, dupChan, readChan)-import           Control.Monad.IO.Class (liftIO)-import           Data.Conduit (($=))-import qualified Data.Conduit as C-import qualified Data.Conduit.List as CL-import           Network.HTTP.Types (status200)-import           Network.Wai (Application, Response(..))--import Network.Wai.EventSource.EventStream---- | Make a new WAI EventSource application reading events from--- the given channel.-eventSourceApp :: Chan ServerEvent -> Application-eventSourceApp = eventSourceAppChan-{-# DEPRECATED eventSourceApp "Use evnetSourceAppChan instead." #-}---- | Make a new WAI EventSource application reading events from--- the given channel.-eventSourceAppChan :: Chan ServerEvent -> Application-eventSourceAppChan chan _ = do-  chan' <- liftIO $ dupChan chan-  return $ response chanToSource chan'---- | Make a new WAI EventSource application reading events from--- the given source.-eventSourceAppSource :: C.Source IO ServerEvent -> Application-eventSourceAppSource src _ = return $ response sourceToSource src---- | Make a new WAI EventSource application reading events from--- the given IO action.-eventSourceAppIO :: IO ServerEvent -> Application-eventSourceAppIO act _ = return $ response ioToSource act--response :: (a -> C.Source IO (C.Flush Builder)) -> a -> Response-response f a = ResponseSource status200 [("Content-Type", "text/event-stream")] $ f a--chanToSource :: Chan ServerEvent -> C.Source IO (C.Flush Builder)-chanToSource chan =-    C.sourceState Nothing pull-  where-    pull Nothing = do-        x <- liftIO $ readChan chan-        return $ case eventToBuilder x of-            Nothing -> C.StateClosed-            Just y -> C.StateOpen (Just C.Flush) (C.Chunk y)-    pull (Just x) = return $ C.StateOpen Nothing x--ioToSource :: IO ServerEvent -> C.Source IO (C.Flush Builder)-ioToSource act =-    C.sourceState Nothing pull-  where-    pull Nothing = do-        x <- liftIO act-        return $ case eventToBuilder x of-            Nothing -> C.StateClosed-            Just y -> C.StateOpen (Just C.Flush) (C.Chunk y)-    pull (Just x) = return $ C.StateOpen Nothing x--sourceToSource :: C.Source IO ServerEvent -> C.Source IO (C.Flush Builder)-sourceToSource src = src $= CL.concatMap eventToFlushBuilder-  where-    eventToFlushBuilder event =-        case eventToBuilder event of-            Nothing -> []-            Just x -> [C.Chunk x, C.Flush]
− src/Network/Wai/EventSource/EventStream.hs
@@ -1,83 +0,0 @@-{-# LANGUAGE OverloadedStrings #-}-{- code adapted by Mathias Billman originaly from Chris Smith https://github.com/cdsmith/gloss-web -}--{-|-    A WAI adapter to the HTML5 Server-Sent Events API.  Push-mode and-    pull-mode interfaces are both available.--}-module Network.Wai.EventSource.EventStream (-    ServerEvent(..),-    eventToBuilder-    ) where--import Blaze.ByteString.Builder-import Blaze.ByteString.Builder.Char8-import Data.Monoid--{-|-    Type representing a communication over an event stream.  This can be an-    actual event, a comment, a modification to the retry timer, or a special-    "close" event indicating the server should close the connection.--}-data ServerEvent-    = ServerEvent {-        eventName :: Maybe Builder,-        eventId   :: Maybe Builder,-        eventData :: [Builder]-        }-    | CommentEvent {-        eventComment :: Builder-        }-    | RetryEvent {-        eventRetry :: Int-        }-    | CloseEvent---{-|-    Newline as a Builder.--}-nl :: Builder-nl = fromChar '\n'---{-|-    Field names as Builder--}-nameField, idField, dataField, retryField, commentField :: Builder-nameField = fromString "event:"-idField = fromString "id:"-dataField = fromString "data:"-retryField = fromString "retry:"-commentField = fromChar ':'---{-|-    Wraps the text as a labeled field of an event stream.--}-field :: Builder -> Builder -> Builder-field l b = l `mappend` b `mappend` nl---{-|-    Appends a buffer flush to the end of a Builder.--}-flushAfter :: Builder -> Builder-flushAfter b = b `mappend` flush---{-|-    Converts a 'ServerEvent' to its wire representation as specified by the-    @text/event-stream@ content type.--}-eventToBuilder :: ServerEvent -> Maybe Builder-eventToBuilder (CommentEvent txt) = Just $ flushAfter $ field commentField txt-eventToBuilder (RetryEvent   n)   = Just $ flushAfter $ field retryField (fromShow n)-eventToBuilder (CloseEvent)       = Nothing-eventToBuilder (ServerEvent n i d)= Just $ flushAfter $-    (name n $ evid i $ mconcat (map (field dataField) d)) `mappend` nl-  where-    name Nothing  = id-    name (Just n') = mappend (field nameField n')-    evid Nothing  = id-    evid (Just i') = mappend (field idField   i')
wai-eventsource.cabal view
@@ -1,33 +1,16 @@ Name:                wai-eventsource-Version:             1.1.0.1-Synopsis:            WAI support for server-sent events-Description:         WAI support for server-sent events-License:             BSD3+Version:             3.0.0+Synopsis:            WAI support for server-sent events (deprecated)+Description:         Since WAI 3.0, this code has been merged into wai-extra.+License:             MIT Author:              Chris Smith, Mathias Biilmann Christensen Maintainer:          greg@gregweber.info Stability:           Experimental Category:            Web Build-type:          Simple Cabal-version:       >=1.8-homepage:            http://www.yesodweb.com/book/wai+homepage:            http://www.yesodweb.com/book/web-application-interface license-file:        LICENSE  Library-  Build-depends:-      base                      >= 4.3 && < 5-    , bytestring                >= 0.9.1.4  && < 0.10-    , blaze-builder             >= 0.3 && < 0.4-    , conduit                   >= 0.2      && < 0.3-    , http-types                >= 0.6      && < 0.7-    , wai                       >= 1.1-    , warp                      >= 1.1-    , transformers--  ghc-options:     -Wall-  hs-source-dirs:  src-  exposed-modules: Network.Wai.EventSource-  other-modules:   Network.Wai.EventSource.EventStream--source-repository head-  type:     git-  location: git://github.com/yesodweb/wai.git+    build-depends: wai >= 3.0