hack2 2011.6.10 → 2011.6.19
raw patch · 3 files changed
+38/−26 lines, 3 filesdep +enumeratorPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: enumerator
API changes (from Hackage documentation)
- Hack2: instance Eq Env
- Hack2: instance Eq Response
+ Hack2: HackEnumerator :: (forall a. Enumerator ByteString IO a) -> HackEnumerator
+ Hack2: instance Default HackEnumerator
+ Hack2: instance Show HackEnumerator
+ Hack2: newtype HackEnumerator
+ Hack2: unHackEnumerator :: HackEnumerator -> (forall a. Enumerator ByteString IO a)
- Hack2: Env :: RequestMethod -> ByteString -> ByteString -> ByteString -> ByteString -> Int -> [(ByteString, ByteString)] -> (Int, Int, Int) -> HackUrlScheme -> ByteString -> HackErrors -> [(ByteString, ByteString)] -> Env
+ Hack2: Env :: RequestMethod -> ByteString -> ByteString -> ByteString -> ByteString -> Int -> [(ByteString, ByteString)] -> (Int, Int, Int) -> HackUrlScheme -> HackEnumerator -> HackErrors -> [(ByteString, ByteString)] -> Env
- Hack2: Response :: Int -> [(ByteString, ByteString)] -> ByteString -> Response
+ Hack2: Response :: Int -> [(ByteString, ByteString)] -> HackEnumerator -> Response
- Hack2: body :: Response -> ByteString
+ Hack2: body :: Response -> HackEnumerator
- Hack2: hackInput :: Env -> ByteString
+ Hack2: hackInput :: Env -> HackEnumerator
Files
- hack2.cabal +2/−2
- readme.md +15/−17
- src/Hack2.hs +21/−7
hack2.cabal view
@@ -1,5 +1,5 @@ Name: hack2-Version: 2011.6.10+Version: 2011.6.19 Build-type: Simple Synopsis: a Haskell Webserver Interface (V2) Description:@@ -18,7 +18,7 @@ library ghc-options: -Wall- build-depends: base >= 3 && < 5, data-default >= 0.2, bytestring+ build-depends: base >= 3 && < 5, data-default >= 0.2, bytestring, enumerator < 5 hs-source-dirs: src/ exposed-modules: Hack2
readme.md view
@@ -78,7 +78,7 @@ ### pick a backend - cabal install hack2-handler-happstack+ cabal install hack2-handler-happstack-server ### Create a Hack app @@ -108,22 +108,20 @@ Middleware ----------- -(below is waiting to be finished)--------------------------------------------- ### demo usage of middleware -install hack-contrib:+install hack2-contrib: - cabal install hack-contrib+ cabal install hack2-contrib put the following in `Main.hs`. This code uses the `URLMap` middleware to route both `/hello` and `/there` to the `say` application. - import Hack- import Hack.Handler.HappstackServer- import Hack.Contrib.Utils- import Hack.Contrib.Middleware.URLMap+ {-# LANGUAGE OverloadedStrings #-}+ + import Hack2+ import Hack2.Handler.HappstackServer+ import Hack2.Contrib.Utils+ import Hack2.Contrib.Middleware.URLMap import Data.ByteString.Lazy.Char8 (pack) import Data.Default @@ -137,7 +135,7 @@ ### create a middleware -inside Hack.hs:+inside Hack2.hs: type Middleware = Application -> Application @@ -149,9 +147,9 @@ finally the source code of `Config.hs`: - module Hack.Contrib.Middleware.Config (config) where+ module Hack2.Contrib.Middleware.Config (config) where - import Hack+ import Hack2 config :: (Env -> Env) -> Middleware config alter app = \env -> app (alter env)@@ -159,7 +157,7 @@ ### Use the middleware stack -From `Hack.Contrib.Utils`:+From `Hack2.Contrib.Utils`: -- usage: use [content_type, cache] app use :: [Middleware] -> Middleware@@ -168,7 +166,7 @@ Handlers -------- -Once an application is written using Hack, it should work on any web server that provides a Hack handler.+Once an application is written using Hack2, it should work on any web server that provides a Hack2 handler. A handler should expose at least one function of type: @@ -177,7 +175,7 @@ Upgrade ------- -With every new release, any library links to hack should be recompiled against the new version, usually as simple as:+With every new release, any library links to Hacks should be recompiled against the new version, usually as simple as: cabal install linked_lib --reinstall
src/Hack2.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE ExistentialQuantification #-}+{-# LANGUAGE Rank2Types #-}+ module Hack2 where import Data.Default (def, Default)@@ -5,7 +8,10 @@ import Data.ByteString.Lazy (ByteString) import qualified Data.ByteString.Lazy as B+import qualified Data.ByteString as Strict +import Data.Enumerator (Enumerator, enumEOF)+ type Application = Env -> IO Response type Middleware = Application -> Application @@ -33,6 +39,14 @@ instance Eq HackErrors where _ == _ = True +newtype HackEnumerator = HackEnumerator { unHackEnumerator :: (forall a. Enumerator Strict.ByteString IO a) }++instance Show HackEnumerator where+ show _ = "HackEnumerator"++instance Default HackEnumerator where+ def = HackEnumerator enumEOF+ data Env = Env { requestMethod :: RequestMethod , scriptName :: ByteString@@ -43,18 +57,18 @@ , httpHeaders :: [(ByteString, ByteString)] , hackVersion :: (Int, Int, Int) , hackUrlScheme :: HackUrlScheme- , hackInput :: ByteString+ , hackInput :: HackEnumerator , hackErrors :: HackErrors , hackHeaders :: [(ByteString, ByteString)] }- deriving (Show, Eq)+ deriving (Show) data Response = Response { status :: Int , headers :: [(ByteString, ByteString)]- , body :: ByteString+ , body :: HackEnumerator }- deriving (Show, Eq)+ deriving (Show) instance Default RequestMethod where def = GET@@ -67,7 +81,7 @@ { status = 200 , headers = []- , body = B.empty+ , body = def } instance Default Env where@@ -82,9 +96,9 @@ , httpHeaders = def , hackVersion = currentVersion , hackUrlScheme = def- , hackInput = B.empty+ , hackInput = def , hackErrors = def , hackHeaders = def } where- currentVersion = (2011, 6, 10)+ currentVersion = (2011, 6, 19)