packages feed

hack 2009.4.30 → 2009.4.51

raw patch · 4 files changed

+83/−51 lines, 4 filesdep +utf8-stringPVP ok

version bump matches the API change (PVP)

Dependencies added: utf8-string

API changes (from Hackage documentation)

+ Hack: version :: [Int]

Files

changelog.md view
@@ -1,3 +1,17 @@+2009.4.51+---------++### Feature++* add documentation++2009.4.50+---------++### Feature++* add version info in default+ 2009.4.30 ---------- 
hack.cabal view
@@ -1,5 +1,5 @@ Name:                 hack-Version:              2009.4.30+Version:              2009.4.51 Build-type:           Simple Synopsis:             a sexy Haskell Webserver Interface Description:@@ -20,7 +20,7 @@  library   ghc-options: -Wall-  build-depends: base, data-default >= 0.2+  build-depends: base, data-default >= 0.2, utf8-string >= 0.3.4   hs-source-dirs: src/   exposed-modules:                       Hack
readme.md view
@@ -2,8 +2,22 @@ ========================================  -Hack is a brain-dead port of the brilliant Ruby [Rack](http://rack.rubyforge.org/) webserver interface.+Hack is a brain-dead port of the brilliant Ruby [Rack](http://rack.rubyforge.org/) webserver interface.  +Hack is made of 3 parts:++* hack: the spec+* hack-contrib: middleware+* hack-handler: drivers++The spec should be as stable as possible, hack-contrib is about middleware and tools, and hack-handler provides server connectivity.++Hack explained in one line+--------------------------++    type Application = Env -> IO Response++ What does a Hack app look like ------------------------------ @@ -11,7 +25,7 @@     module Main where      import Hack-    import Hack.Handler.Hyena+    import Hack.Handler.Happstack      hello :: Application     hello = \env -> return $ Response @@ -29,19 +43,16 @@      cabal update     -### install hyena--    git clone git://github.com/tibbe/hyena.git-    cd hyena-    cabal install- ### install hack -    cabal install happy;-    cabal install hack;+    cabal install happy+    cabal install hack     cabal install hack-contrib-    cabal install hack-handler-hyena +### pick a backend++    cabal install hack-handler-happstack+ ### Create a Hack app  put the following code in `src/Main.hs`@@ -49,7 +60,7 @@     module Main where      import Hack-    import Hack.Handler.Hyena+    import Hack.Handler.Happstack      hello :: Application     hello = \env -> return $ Response @@ -76,17 +87,14 @@     module Main where      import Hack-    import Hack.Handler.Hyena+    import Hack.Handler.Happstack     import Hack.Contrib.Utils-    import Hack.Contrib.Middleware.SimpleRoute-+    import Hack.Contrib.Middleware.SimpleRouter      import Data.Default-    import MPS-    import Prelude hiding ((.))          hello :: Application-    hello = \env -> def {body = env.show} .return+    hello = \env -> return $ def {body = show env}      app :: Application     app = route [("/hello", hello), ("", hello)] empty_app@@ -105,9 +113,7 @@  just pass an applied middleware into a chain. -finally the source code of SimpleRoute.hs:--    {-# LANGUAGE QuasiQuotes #-}+finally the source code of SimpleRouter.hs:      module Hack.Contrib.Middleware.SimpleRouter where @@ -135,7 +141,7 @@  ### Use the middleware stack -Rack provides a builder DSL, Hack just use a function. From `Utils.hs`:+Rack provides a builder DSL, Hack just use a function. From `Contrib.Utils.hs`:      -- usage: app.use [content_type, cache]     use :: [Middleware] -> Middleware@@ -144,7 +150,6 @@ Handlers -------- - Just like Rack, once an application is written using Hack, it should work on any web server that provides a Hack handler. I'm only familiar with Kibro, so it became the first handler that's included.  The handler should expose only one function of type:@@ -161,9 +166,16 @@ Links ----- +### Resources++* [hack-contrib](http://github.com/nfjinjing/hack-contrib)+* [hack-handler-kibro](http://github.com/nfjinjing/hack-handler-kibro)+* [hack-handler-hyena](http://github.com/nfjinjing/hack-handler-hyena)+* [hack-handler-happstack](http://github.com/nfjinjing/hack-handler-happstack)++### Reference+ * [Rack](http://rack.rubyforge.org/ ) * [Rack wiki](http://wiki.github.com/rack/rack)-* [Rack source](http://github.com/rack/rack/tree/master )-* [rack-contrib source](http://github.com/rack/rack-contrib/tree/master)+* [rack-contrib](http://github.com/rack/rack-contrib/tree/master) * [Hyena](http://github.com/tibbe/hyena/tree/master)-
src/Hack.hs view
@@ -1,9 +1,15 @@ {-# LANGUAGE TypeSynonymInstances #-} +-- | Hack spec! Stolen from Rack with some simplification. module Hack where  import Data.Default+import System.IO.UTF8+import System.IO (stderr) +version :: [Int]+version = [2009, 4, 51]+ data RequestMethod =      OPTIONS   |  GET@@ -19,37 +25,37 @@  type Map = [(String, String)] --- newtype HackErrors = HackErrors { unHackErrors :: String -> IO () }- type Stream = String -> IO ()++-- | customizable error stream type HackErrors = Stream  instance Show HackErrors where-  show _ = "HackHackErrors"+  show _ = "HackErrors"  data Env = Env -  {  request_method :: RequestMethod-  ,  script_name :: String-  ,  path_info :: String-  ,  query_string :: String-  ,  server_name :: String-  ,  server_port :: Int-  ,  http :: Map-  ,  hack_version :: [Int]-  ,  hack_url_scheme :: Hack_UrlScheme-  ,  hack_input :: String-  ,  hack_errors :: HackErrors-  ,  hack_multithread :: Bool-  ,  hack_multiprocess :: Bool-  ,  hack_run_once :: Bool-  ,  custom :: Map+  {  request_method :: RequestMethod            -- ^ HTTP request method  +  ,  script_name :: String                      -- ^ The initial portion of the request URL's \"path\" that corresponds to the application object, so that the application knows its virtual \"location\". This may be an empty string, if the application corresponds to the \"root\" of the server.   +  ,  path_info :: String                        -- ^ The remainder of the request URL's \"path\", designating the virtual \"location\" of the request's target within the application. This will always starts with \"/\"+  ,  query_string :: String                     -- ^ The portion of the request URL that follows the ?, if any. May be empty+  ,  server_name :: String                      -- ^ When combined with SCRIPT_NAME and PATH_INFO, these variables can be used to complete the URL. Note, however, that HTTP_HOST, if present, should be used +  ,  server_port :: Int                         -- ^ preference to SERVER_NAME for reconstructing the request URL. SERVER_NAME and SERVER_PORT can never be empty strings, and so are always required.    +  ,  http :: Map                                -- ^ Variables corresponding to the client-supplied HTTP request headers+  ,  hack_version :: [Int]                      -- ^ The Array [0,1], representing this version of Hack+  ,  hack_url_scheme :: Hack_UrlScheme          -- ^ HTTP or HTTPS, depending on the request URL+  ,  hack_input :: String                       -- ^ body of the request+  ,  hack_errors :: HackErrors                  -- ^ error stream+  ,  hack_multithread :: Bool                   -- ^ true if the application object may be simultaneously invoked by another thread in the same process, false otherwise. +  ,  hack_multiprocess :: Bool                  -- ^ true if an equivalent application object may be simultaneously invoked by another process, false otherwise.+  ,  hack_run_once :: Bool                      -- ^ true if the server expects (but does not guarantee!) that the application will only be invoked this one time during the life of its containing process. Normally, this will only be true for a server based on CGI (or something similar). +  ,  custom :: Map                              -- ^ any non HTTP standard header   }   deriving (Show)  data Response = Response -  {  status :: Int-  ,  headers :: Map-  ,  body :: String+  {  status :: Int                              -- ^ must be greater than or equal to 100. +  ,  headers :: Map                             -- ^ 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) seperated by \"\\n\". The lines must not contain characters below 037. +  ,  body :: String                             -- ^ body of the response   }   deriving (Show) @@ -63,8 +69,8 @@   def = Response def def def  instance Default Env where-  def = Env def def def def def def def def def def const_io False False False def-    where const_io = const (return ())+  def = Env def def def def def def def version def def stderr_stream False False False def+    where stderr_stream = hPutStr stderr  type Application = Env -> IO Response