hack2 2011.6.19 → 2011.6.20
raw patch · 3 files changed
+35/−27 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Hack2: instance Eq HackErrors
Files
- hack2.cabal +1/−1
- readme.md +32/−21
- src/Hack2.hs +2/−5
hack2.cabal view
@@ -1,5 +1,5 @@ Name: hack2-Version: 2011.6.19+Version: 2011.6.20 Build-type: Simple Synopsis: a Haskell Webserver Interface (V2) Description:
readme.md view
@@ -6,7 +6,7 @@ Version ------- -> 2011.6.10+> 2011.6.19 Introduction ------------@@ -28,10 +28,17 @@ {-# LANGUAGE OverloadedStrings #-} import Hack2+ import Hack2.Contrib.Response (set_body_bytestring)+ import Hack2.Handler.HappstackServer+ import Data.Default (def) app :: Application- app = \env -> return $- Response 200 [ ("Content-Type", "text/plain") ] "Hello World"+ app = \env -> + return $ + set_body_bytestring "Hello World" $+ Response 200 [ ("Content-Type", "text/plain") ] def++ main = run app Spec@@ -47,7 +54,7 @@ * __httpHeaders__: Variables corresponding to the client-supplied HTTP request headers (e.g. "Accept"). The presence or absence of these variables should correspond with the presence or absence of the appropriate HTTP header in the request. * __hackVersion__: The list of `Int`, representing this version of Hack * __hackUrlScheme__: `HTTP` or `HTTPS`, depending on the request URL. -* __hackInput__: The body of the request.+* __hackInput__: The body of the request, enumerator style. * __hackErrors__: The error stream. * __hackHeaders__: None standard http headers. @@ -56,7 +63,7 @@ * __status__: This is an HTTP status. It must be greater than or equal to 100. * __headers__: The header must not contain a Status key, contain keys with : or newlines in their name, contain keys names that end in - or _, but only contain keys that consist of letters, digits, _ or - and start with a letter. The values of the header must be Strings, consisting of lines (for multiple header values) separated by “\n”. The lines must not contain characters below 037.-* __body__: The body of the response.+* __body__: The body of the response, enumerator style. ### Properties @@ -76,6 +83,10 @@ cabal install hack2 +### install some hack helpers+ + cabal install hack2-contrib+ ### pick a backend cabal install hack2-handler-happstack-server@@ -87,14 +98,15 @@ {-# LANGUAGE OverloadedStrings #-} import Hack2+ import Hack2.Contrib.Response (set_body_bytestring) import Hack2.Handler.HappstackServer+ import Data.Default (def) app :: Application- app = \env -> return $ Response - { status = 200- , headers = [ ("Content-Type", "text/plain") ]- , body = "Hello World"- }+ app = \env -> + return $ + set_body_bytestring "Hello World 2" $ + def { headers = [ ("Content-Type", "text/plain") ] } main = run app @@ -110,23 +122,22 @@ ### demo usage of middleware -install hack2-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. {-# LANGUAGE OverloadedStrings #-}- + import Hack2+ import Hack2.Contrib.Response (set_body_bytestring) import Hack2.Handler.HappstackServer- import Hack2.Contrib.Utils- import Hack2.Contrib.Middleware.URLMap+ import Data.Default (def)+ import Data.ByteString.Lazy.Char8 (pack)- import Data.Default- + import Hack2.Contrib.Utils (empty_app)+ import Hack2.Contrib.Middleware.URLMap++ say :: Application- say = \env -> return $ def {body = pack $ show env, status = 200}+ say = \env -> return $ set_body_bytestring (pack $ show env) def app :: Application app = url_map [("/hello", say), ("/there", say)] empty_app@@ -175,7 +186,7 @@ Upgrade ------- -With every new release, any library links to Hacks should be recompiled against the new version, usually as simple as:+With every new release, any library links to Hack2 should be recompiled against the new version, usually as simple as: cabal install linked_lib --reinstall
src/Hack2.hs view
@@ -6,8 +6,8 @@ import Data.Default (def, Default) import System.IO (stderr) -import Data.ByteString.Lazy (ByteString)-import qualified Data.ByteString.Lazy as B+import Data.ByteString (ByteString)+import qualified Data.ByteString as B import qualified Data.ByteString as Strict import Data.Enumerator (Enumerator, enumEOF)@@ -35,9 +35,6 @@ instance Default HackErrors where def = HackErrors (B.hPutStr stderr)--instance Eq HackErrors where- _ == _ = True newtype HackEnumerator = HackEnumerator { unHackEnumerator :: (forall a. Enumerator Strict.ByteString IO a) }