wai-eventsource 2.0.0.2 → 3.0.0
raw patch · 3 files changed
+4/−163 lines, 3 filesdep −basedep −blaze-builderdep −bytestringdep ~wai
Dependencies removed: base, blaze-builder, bytestring, conduit, http-types, transformers
Dependency ranges changed: wai
Files
- src/Network/Wai/EventSource.hs +0/−67
- src/Network/Wai/EventSource/EventStream.hs +0/−75
- wai-eventsource.cabal +4/−21
− src/Network/Wai/EventSource.hs
@@ -1,67 +0,0 @@-{-# LANGUAGE OverloadedStrings #-}-{-|- A WAI adapter to the HTML5 Server-Sent Events API.--}-module Network.Wai.EventSource (- ServerEvent(..),- eventSourceAppChan,- eventSourceAppSource,- eventSourceAppIO,- sourceToSource- ) 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.List as CL-import Network.HTTP.Types (status200)-import Network.Wai (Application, Response, responseSource)--import Network.Wai.EventSource.EventStream---- | 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 :: 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 -> Source IO (Flush Builder)) -> a -> Response-response f a = responseSource status200 [("Content-Type", "text/event-stream")] $ f a--chanToSource :: Chan ServerEvent -> Source IO (Flush Builder)-chanToSource = ioToSource . readChan--ioToSource :: IO ServerEvent -> Source IO (Flush Builder)-ioToSource act =- loop- where- loop = do- x <- liftIO act- case eventToBuilder x of- Nothing -> return ()- Just y -> do- yield $ Chunk y- yield Flush- loop---- | Convert a ServerEvent source into a Builder source of serialized--- events.-sourceToSource :: Monad m => Source m ServerEvent -> Source m (Flush Builder)-sourceToSource src = src $= CL.concatMap eventToFlushBuilder- where- eventToFlushBuilder event =- case eventToBuilder event of- Nothing -> []- Just x -> [Chunk x, Flush]
− src/Network/Wai/EventSource/EventStream.hs
@@ -1,75 +0,0 @@-{-# LANGUAGE OverloadedStrings #-}-{- code adapted by Mathias Billman originaly from Chris Smith https://github.com/cdsmith/gloss-web -}--{-|- Internal module, usually you don't need to use it.--}-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---{-|- Converts a 'ServerEvent' to its wire representation as specified by the- @text/event-stream@ content type.--}-eventToBuilder :: ServerEvent -> Maybe Builder-eventToBuilder (CommentEvent txt) = Just $ field commentField txt-eventToBuilder (RetryEvent n) = Just $ field retryField (fromShow n)-eventToBuilder (CloseEvent) = Nothing-eventToBuilder (ServerEvent n i d)= Just $- (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,7 +1,7 @@ Name: wai-eventsource-Version: 2.0.0.2-Synopsis: WAI support for server-sent events-Description: WAI support for server-sent events+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@@ -13,21 +13,4 @@ license-file: LICENSE Library- Build-depends:- base >= 4.3 && < 5- , bytestring >= 0.9.1.4- , blaze-builder >= 0.3 && < 0.4- , conduit >= 0.5 && < 1.2- , http-types >= 0.7- , wai >= 2.0 && < 2.2- , transformers-- ghc-options: -Wall- hs-source-dirs: src- exposed-modules:- Network.Wai.EventSource- Network.Wai.EventSource.EventStream--source-repository head- type: git- location: git://github.com/yesodweb/wai.git+ build-depends: wai >= 3.0