packages feed

hack 2009.4.26 → 2009.4.27

raw patch · 5 files changed

+41/−40 lines, 5 files

Files

changelog.md view
@@ -1,3 +1,10 @@+2009.4.27+---------++### Fix++* hyena handler show real message ( Safari won't work without this fix )+ 2009.4.26 --------- 
hack.cabal view
@@ -1,5 +1,5 @@ Name:                 hack-Version:              2009.4.26+Version:              2009.4.27 Build-type:           Simple Synopsis:             a sexy Haskell Webserver Interface Description:
readme.md view
@@ -11,7 +11,7 @@     module Main where      import Hack-    import Hack.Handler.Kibro+    import Hack.Handler.Hyena      hello :: Application     hello = \env -> return $ Response @@ -25,31 +25,19 @@ 1 minute tutorial ----------------- -### Install Hack--    cabal install hack--### Install Kibro (the only handler at the moment)--    cabal install kibro--### Install lighttpd 1.4.19 (used by kibro)--    wget http://www.lighttpd.net/download/lighttpd-1.4.19.tar.gz-    tar zxfv lighttpd-1.4.19.tar.gz-    cd lighttpd-1.4.19-    ./configure --prefix=$HOME-    make-    make install+### update cabal -### Create a new Kibro project+    cabal update+    +### install hyena -    kibro new hello-world+    git clone git://github.com/tibbe/hyena.git+    cd hyena+    cabal install -### Test if Kibro works+### install hack -    cd hello-world-    kibro start+    cabal install hack  ### Create a Hack app @@ -58,7 +46,7 @@     module Main where      import Hack-    import Hack.Handler.Kibro+    import Hack.Handler.Hyena      hello :: Application     hello = \env -> return $ Response @@ -70,10 +58,13 @@     main = run hello  -restart kibro+### run -    kibro restart+    ghc --make -O2 Main.hs+    ./Main +It should be running on [http://127.0.0.1:3000](http://127.0.0.1:3000) now.+ Middleware ----------- @@ -84,7 +75,7 @@     import Hack     import Hack.Utils     import Hack.SimpleRoute-    import Hack.Handler.Kibro+    import Hack.Handler.Hyena      import Data.Default     import MPS@@ -118,14 +109,15 @@      import Hack     import Hack.Utils-    import List (find)++    import MPSUTF8     import Prelude hiding ((.), (^), (>))-    import MPS+    import List (find, isPrefixOf)      type RoutePath = (String, Application)      route :: [RoutePath] -> MiddleWare-    route h _ = \env ->+    route h app = \env ->       let path             = env.path_info           script           = env.script_name           mod_env location = env @@ -133,8 +125,8 @@             , path_info    = path.drop (location.length)             }       in-      case h.find (fst > flip starts_with path) of-        Nothing -> not_found [$here|Not Found: #{path}|]+      case h.find (fst > (`isPrefixOf` path) ) of+        Nothing -> app env         Just (location, app) -> app (mod_env location)  ### Use the middleware stack@@ -169,4 +161,5 @@ * [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)+* [Hyena](http://github.com/tibbe/hyena/tree/master) 
src/Hack/Contrib/Head.hs view
@@ -2,6 +2,7 @@  import Hack import Hack.Utils+import Hack.Response  import MPSUTF8 import Prelude hiding ((.), (^), (>), head)@@ -10,5 +11,5 @@ head app = \env -> do   response <- app env   if env.request_method.is HEAD -    then return $ response { body = "" }+    then return $ response .set_body "" .set_content_length 0     else return $ response
src/Hack/Handler/Hyena.hs view
@@ -51,8 +51,11 @@            Right z'' -> return z''    return yieldBlock-  -hack_response_to_hyena_response r e =++type WaiResponse = (Int, S.ByteString, Wai.Headers, Enumerator)++hack_response_to_hyena_response :: Enumerator -> Hack.Response -> WaiResponse+hack_response_to_hyena_response e r =     (   r.status     ,   r.status.show_status_code.fromMaybe "OK" .to_b     ,   r.Hack.headers.map both_to_b@@ -67,12 +70,9 @@   r <- app hack_env      enum <- r.body.enum_string-  -  let hyena_status = r.status-  let hyena_status_message = r.status.show.to_b-  let hyena_headers = r.Hack.headers.map both_to_b+  let hyena_response = r.hack_response_to_hyena_response enum   -  return (hyena_status, hyena_status_message, hyena_headers, enum)+  return hyena_response -- (hyena_status, hyena_status_message, hyena_headers, enum)    run app = app.hack_to_wai.serve