packages feed

hack-handler-hyena 2010.1.18 → 2010.3.15

raw patch · 4 files changed

+29/−36 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

changelog.md view
@@ -1,3 +1,11 @@+2010.3.15+---------++### Fix++* merged Josh's fork, hyena respect the runWithConfig { port } flag+* clean up code+ 2010.1.17 --------- 
hack-handler-hyena.cabal view
@@ -1,5 +1,5 @@ Name:                 hack-handler-hyena-Version:              2010.1.18+Version:              2010.3.15 Build-type:           Simple Synopsis:             Hyena hack handler Description:          Hyena hack handler
readme.md view
@@ -1,18 +1,6 @@-### Config--to use a different port, start with (default port is 3000)--    ./main -p 3000--It's the same as the hyena config.--Also use runWithConfig to put your custom port into Env, otherwise, your app won't get this port information.--    runWithConfig (def {port = 3000}) your_app--### In practice+### Note -You must set content-length in response explicitly, e.g. use the conetnt_length middleware+You must set content-length in response explicitly, e.g. use the content_length middleware, otherwise, request might choke.      import Hack.Handler.Hyena     import Hack.Contrib.Middleware.ContentLength@@ -25,5 +13,6 @@       createTemplateIfMissing conf       createRepoIfMissing conf       initializeGititState conf+             run . content_length $ serverPartToApp (wiki conf)     
src/Hack/Handler/Hyena.hs view
@@ -6,7 +6,7 @@ import qualified Hack as Hack import Hyena.Server import Network.Wai as Wai-+import qualified Hyena.Config as Hyena.Config  import Prelude hiding ((.), (^)) import System.IO@@ -28,24 +28,15 @@ a . f = f a infixl 9 . --- | this won't change the port or servername for hyena, use---   ./main -p 3000 to configure port---   this just make sure port and serverName are presented in Env data ServerConf = ServerConf { port :: Int, serverName :: String } instance Default ServerConf where   def = ServerConf { port = 3000, serverName = "localhost" } -to_s :: S.ByteString -> String-to_s = C.unpack--to_b :: String -> S.ByteString-to_b = C.pack--both_to_s :: (S.ByteString, S.ByteString) -> (String, String)-both_to_s (x,y) = (to_s x, to_s y)+unpack_tuple :: (S.ByteString, S.ByteString) -> (String, String)+unpack_tuple (x,y) = (C.unpack x, C.unpack y) -both_to_b :: (String, String) -> (S.ByteString, S.ByteString)-both_to_b (x,y) = (to_b x, to_b y)+pack_tuple :: (String, String) -> (S.ByteString, S.ByteString)+pack_tuple (x,y) = (C.pack x, C.pack y)  hyena_env_to_hack_env :: ServerConf -> Environment -> IO Hack.Env hyena_env_to_hack_env conf e = do@@ -53,10 +44,10 @@   return def     {           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.scriptName    = e.scriptName.C.unpack+    ,  Hack.pathInfo      = e.pathInfo.C.unpack+    ,  Hack.queryString   = e.queryString .fromMaybe C.empty .C.unpack+    ,  Hack.http          = e.Wai.headers .map unpack_tuple     ,  Hack.hackErrors    = e.errors     ,  Hack.serverPort    = conf.port     ,  Hack.serverName    = conf.serverName@@ -93,8 +84,8 @@ hack_response_to_hyena_response :: Enumerator -> Hack.Response -> WaiResponse hack_response_to_hyena_response e r =     (   r.Hack.status-    ,   r.Hack.status.show_status_message.fromMaybe "OK" .to_b-    ,   r.Hack.headers.map both_to_b+    ,   r.Hack.status.show_status_message.fromMaybe "OK" .C.pack+    ,   r.Hack.headers.map pack_tuple     ,   e     ) @@ -114,7 +105,12 @@ run app = runWithConfig def app  runWithConfig :: ServerConf -> Hack.Application -> IO ()-runWithConfig conf app = app.hack_to_wai_with_config conf .serve+runWithConfig conf app = do+  hyena_config <- Hyena.Config.configFromFlags+  let hyena_config_with_port =+          hyena_config { Hyena.Config.port = port conf+                       }+  app.hack_to_wai_with_config conf .(serveWithConfig hyena_config_with_port)   show_status_message :: Int -> Maybe String