hack-handler-hyena 2009.4.51 → 2009.6.23
raw patch · 7 files changed
+95/−16 lines, 7 filesdep −cgidep ~basedep ~hackdep ~hyena
Dependencies removed: cgi
Dependency ranges changed: base, hack, hyena
Files
- Nemesis +36/−0
- changelog.md +14/−0
- hack-handler-hyena.cabal +3/−3
- known-issues.md +1/−0
- readme.md +5/−1
- src/Hack/Handler/Hyena.hs +22/−12
- src/Test.hs +14/−0
+ Nemesis view
@@ -0,0 +1,36 @@+nemesis = do+ + clean+ [ "**/*.hi"+ , "**/*.o"+ , "manifest"+ , "main"+ , "nemesis-tmp.*"+ , "Test"+ ]+ ++ desc "prepare cabal dist"+ task "dist" $ do+ sh "cabal clean"+ sh "cabal configure"+ sh "cabal sdist"+++ desc "put all .hs files in manifest"+ task "manifest" $ do+ sh "find . | grep 'hs$' > manifest"+++ desc "start console"+ task "i" (sh "ghci -isrc src/Hack/Handler/Hyena.hs")++ desc "test"+ task "test" $ do+ sh "ghc --make -isrc src/Test.hs -o Test"+ sh "echo ready..."+ sh "./Test"+ + desc "show sloc"+ task "stat" $ do+ sh "cloc -match-f=hs$ --quiet src"
changelog.md view
@@ -1,3 +1,17 @@+2009.6.23+---------++### Feature++* compatible with hack 5.19 and hyena 0.1++2009.5.19+---------++### Feature++* Compatible with hack 5.19+ 2009.4.51 ---------
hack-handler-hyena.cabal view
@@ -1,5 +1,5 @@ Name: hack-handler-hyena-Version: 2009.4.51+Version: 2009.6.23 Build-type: Simple Synopsis: Hyena hack handler Description: Hyena hack handler@@ -11,11 +11,11 @@ Cabal-version: >= 1.2 category: Web homepage: http://github.com/nfjinjing/hack/tree/master-data-files: readme.md, changelog.md+data-files: readme.md, changelog.md, known-issues.md, Nemesis, src/Test.hs library ghc-options: -Wall- build-depends: base, cgi, network, bytestring, data-default >= 0.2, hack >= 2009.4.51, hyena, containers+ build-depends: base >= 4.0 && < 5, network, bytestring, data-default >= 0.2, hack >= 2009.5.19, hyena >= 0.1, containers hs-source-dirs: src/ exposed-modules: Hack.Handler.Hyena
+ known-issues.md view
@@ -0,0 +1,1 @@+* there is a bug in the handler, which prevents hack to server large binary files, e.g. `Hack.Contrib.Middleware.Static` won't work properly
readme.md view
@@ -1,1 +1,5 @@-Hyena handler+to use a different port, start with++ ./main -p 3456++It's the same as the hyena config.
src/Hack/Handler/Hyena.hs view
@@ -3,7 +3,7 @@ module Hack.Handler.Hyena (run) where -import Hack as Hack+import qualified Hack as Hack import Hyena.Server import Network.Wai as Wai @@ -17,6 +17,7 @@ import Data.Char import qualified Data.ByteString.Char8 as C import qualified Data.ByteString as S+import qualified Data.ByteString.Lazy.Char8 as L import qualified Data.Map as M (.) :: a -> (a -> b) -> b@@ -39,17 +40,26 @@ hyena_env_to_hack_env e = return $ def { - request_method = requestMethod.show.map toUpper.read- , script_name = e.scriptName.to_s- , path_info = e.pathInfo.to_s- , query_string = e.queryString .fromMaybe (to_b "") .to_s- , http = e.Wai.headers .map both_to_s- , hack_errors = e.errors+ Hack.requestMethod = convertRequestMethod (e.requestMethod)+ , Hack.scriptName = e.scriptName.to_s+ , Hack.pathInfo = e.pathInfo.to_s+ , Hack.queryString = e.queryString .fromMaybe (to_b "") .to_s+ , Hack.http = e.Wai.headers .map both_to_s+ , Hack.hackErrors = e.errors }+ where+ convertRequestMethod Wai.Options = Hack.OPTIONS+ convertRequestMethod Wai.Get = Hack.GET+ convertRequestMethod Wai.Head = Hack.HEAD+ convertRequestMethod Wai.Post = Hack.POST+ convertRequestMethod Wai.Put = Hack.PUT+ convertRequestMethod Wai.Delete = Hack.DELETE+ convertRequestMethod Wai.Trace = Hack.TRACE+ convertRequestMethod Wai.Connect = Hack.CONNECT -enum_string :: String -> IO Enumerator+enum_string :: L.ByteString -> IO Enumerator enum_string msg = do- let s = msg.to_b+ let s = msg.L.unpack.to_b let yieldBlock f z = do z' <- f z s case z' of@@ -62,8 +72,8 @@ hack_response_to_hyena_response :: Enumerator -> Hack.Response -> WaiResponse hack_response_to_hyena_response e r =- ( r.status- , r.status.show_status_message.fromMaybe "OK" .to_b+ ( r.Hack.status+ , r.Hack.status.show_status_message.fromMaybe "OK" .to_b , r.Hack.headers.map both_to_b , e )@@ -75,7 +85,7 @@ r <- app hack_env - enum <- r.body.enum_string+ enum <- r.Hack.body.enum_string let hyena_response = r.hack_response_to_hyena_response enum return hyena_response
+ src/Test.hs view
@@ -0,0 +1,14 @@+module Main where++import Hack+import Hack.Handler.Hyena+import Hack.Contrib.Middleware.Inspect+import Hack.Contrib.Middleware.Debug+import Hack.Contrib.Utils+import Data.ByteString.Lazy.Char8 (pack)++app :: Application+app = \env -> return $+ Response 200 [ ("Content-Type", "text/plain") ] (pack "Hello World")++main = run $ use [debug (\e r -> print e), inspect] app