packages feed

wai-extra 3.0.20.0 → 3.0.20.1

raw patch · 6 files changed

+97/−2 lines, 6 filesdep +warpdep ~basedep ~blaze-builderdep ~http-typesnew-component:exe:examplePVP ok

version bump matches the API change (PVP)

Dependencies added: warp

Dependency ranges changed: base, blaze-builder, http-types, time, wai

API changes (from Hackage documentation)

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+## 3.0.20.1++* Set `requestBodyLength` for `srequest` [#654](https://github.com/yesodweb/wai/pull/654)+ ## 3.0.20.0  * runSessionWith (runSession variant that gives access to ClientState) [#629](https://github.com/yesodweb/wai/pull/629)
Network/Wai/EventSource.hs view
@@ -1,5 +1,10 @@ {-|     A WAI adapter to the HTML5 Server-Sent Events API.++    If running through a proxy like Nginx you might need to add the+    headers:++    > [ ("X-Accel-Buffering", "no"), ("Cache-Control", "no-cache")] -} module Network.Wai.EventSource (     ServerEvent(..),
Network/Wai/Test.hs view
@@ -176,6 +176,7 @@                 case bss of                     [] -> ([], S.empty)                     x:y -> (y, x)+            , requestBodyLength = KnownLength $ fromIntegral $ L.length bod             }     req'' <- addCookiesToRequest req'     response <- liftIO $ do
README.md view
@@ -1,3 +1,16 @@-## wai-extra+# wai-extra  The goal here is to provide common features without many dependencies.+++## Example using Server-Sent Events ##++There is a small example using Server-Sent Events (SSE) in the+`./example` directory.++Run the commands below to start the server on http://localhost:8080++```+$ stack build .+$ stack exec example+```
+ example/Main.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE OverloadedStrings #-}+module Main where++import Blaze.ByteString.Builder.Char.Utf8 (fromString)+import Control.Concurrent (forkIO, threadDelay)+import Control.Concurrent.Chan+import Control.Monad+import Data.Time.Clock.POSIX (getPOSIXTime)+import Network.HTTP.Types (status200)+import Network.Wai (Application, Middleware, pathInfo, responseFile)+import Network.Wai.EventSource (ServerEvent(..), eventSourceAppChan, eventSourceAppIO)+import Network.Wai.Handler.Warp (run)+import Network.Wai.Middleware.AddHeaders (addHeaders)+import Network.Wai.Middleware.Gzip (gzip, def)+++app :: Chan ServerEvent -> Application+app chan req respond =+    case pathInfo req of+        []     -> respond $ responseFile status200 [("Content-Type", "text/html")] "example/index.html" Nothing+        ["esold"]  -> eventSourceAppChan chan req respond+        ["eschan"] -> eventSourceAppChan chan req respond+        ["esio"]   -> eventSourceAppIO eventIO req respond+        _ -> error "unexpected pathInfo"++eventChan :: Chan ServerEvent -> IO ()+eventChan chan = forever $ do+    threadDelay 1000000+    time <- getPOSIXTime+    writeChan chan (ServerEvent Nothing Nothing [fromString . show $ time])++eventIO :: IO ServerEvent+eventIO = do+    threadDelay 1000000+    time <- getPOSIXTime+    return $ ServerEvent (Just $ fromString "io")+                         Nothing+                         [fromString . show $ time]++main :: IO ()+main = do+    chan <- newChan+    _ <- forkIO . eventChan $ chan+    run 8080 (gzip def $ headers $ app chan)+    where+      -- headers required for SSE to work through nginx+      -- not required if using warp directly+      headers :: Middleware+      headers = addHeaders [ ("X-Accel-Buffering", "no")+                           , ("Cache-Control", "no-cache")+                           ]
wai-extra.cabal view
@@ -1,5 +1,5 @@ Name:                wai-extra-Version:             3.0.20.0+Version:             3.0.20.1 Synopsis:            Provides some basic WAI handlers and middleware. description:   Provides basic WAI handler and middleware functionality:@@ -81,6 +81,11 @@   ChangeLog.md   README.md +flag build-example+  description:        Build example executable.+  manual:             True+  default:            False+ Library   Build-Depends:     base                      >= 4.6 && < 5                    , bytestring                >= 0.9.1.4@@ -154,6 +159,22 @@   other-modules:     Network.Wai.Middleware.RequestLogger.Internal   default-language:          Haskell2010   ghc-options:       -Wall++executable example+  hs-source-dirs:      example+  main-is:             Main.hs+  ghc-options:         -threaded -rtsopts -with-rtsopts=-N -Wall+  if flag(build-example)+    build-depends:     base+                     , wai-extra+                     , warp+                     , wai+                     , time+                     , http-types+                     , blaze-builder+  else+    buildable: False+  default-language:    Haskell2010  test-suite spec     type:            exitcode-stdio-1.0