packages feed

hack2-handler-happstack-server 2011.6.10 → 2011.6.19

raw patch · 2 files changed

+46/−14 lines, 2 filesdep +enumeratordep ~hack2PVP ok

version bump matches the API change (PVP)

Dependencies added: enumerator

Dependency ranges changed: hack2

API changes (from Hackage documentation)

Files

hack2-handler-happstack-server.cabal view
@@ -1,5 +1,5 @@ Name:                 hack2-handler-happstack-server-Version:              2011.6.10+Version:              2011.6.19 Build-type:           Simple Synopsis:             Hack2 Happstack server handler Description:          Hack2 Happstack server handler@@ -10,12 +10,23 @@ Build-Depends:        base Cabal-version:        >= 1.2 category:             Web-homepage:             http://github.com/nfjinjing/hack2-handler-happstack-server+homepage:             https://github.com/nfjinjing/hack2-handler-happstack-server data-files:           readme.md, changelog.md, Nemesis  library-  ghc-options: -Wall-  build-depends: base >= 4.0 && < 5, cgi, network, bytestring, data-default >= 0.2, hack2 >= 2011.6.10, happstack-server < 6, containers, mtl++  build-depends: +                      base >= 4.0 && < 5+                    , cgi+                    , network+                    , bytestring+                    , data-default >= 0.2+                    , hack2 >= 2011.6.19+                    , happstack-server < 6+                    , containers+                    , mtl+                    , enumerator < 5+                       hs-source-dirs: src/   exposed-modules:                       Hack2.Handler.HappstackServer
src/Hack2/Handler/HappstackServer.hs view
@@ -25,6 +25,24 @@ import qualified Data.Map as M import qualified Happstack.Server.SimpleHTTP as H ++-- enum helper start+import qualified Data.ByteString.Char8 as Strict+import qualified Data.ByteString.Lazy.Char8 as B++import qualified Data.Enumerator.Binary as EB+import qualified Data.Enumerator.List as EL++import Data.Enumerator (run_, enumList, Enumerator, ($$))++fromEnumerator :: Monad m => Enumerator Strict.ByteString m B.ByteString -> m B.ByteString+fromEnumerator m = run_ $ m $$ EB.consume++toEnumerator :: Monad m => B.ByteString -> Enumerator Strict.ByteString m a+toEnumerator = enumList 1 . B.toChunks+-- enum helper end++ data ServerConf = ServerConf { port :: Int, serverName :: L.ByteString }   deriving (Show) @@ -38,7 +56,7 @@ run = runWithConfig def  appToServerPart :: ServerConf -> Hack2.Application -> ServerPart (Happstack.Response)-appToServerPart conf app = askRq >>= liftIO . (hackRToServerPartR <$>) . app . reqToEnv+appToServerPart conf app = askRq >>= \req -> liftIO $ (app $ reqToEnv req) >>= hackRToServerPartR   where     reqToEnv req =       def@@ -49,7 +67,7 @@         , Hack2.serverName      = serverName conf         , Hack2.serverPort      = (snd $ rqPeer req)         , Hack2.httpHeaders     = headersToHttp (rqHeaders req)-        , Hack2.hackInput       = (\(Body x) -> x) (rqBody req)+        , Hack2.hackInput       = Hack2.HackEnumerator $ toEnumerator $ (\(Body x) -> x) (rqBody req)         , Hack2.hackHeaders     = [("RemoteHost", L.pack $ fst $ rqPeer req)]         }     @@ -71,14 +89,17 @@     headerToPair (HeaderPair k v) =        (L.pack $ normalizeHeader $ S.unpack k, s2l $ S.intercalate " " v) -hackRToServerPartR :: Hack2.Response -> Happstack.Response-hackRToServerPartR r = Happstack.Response -  { rsCode      = Hack2.status r-  , rsHeaders   = httpToHeaders $ Hack2.headers r-  , rsFlags     = RsFlags {rsfContentLength = False}-  , rsBody      = Hack2.body r-  , rsValidator = Nothing -  }+hackRToServerPartR :: Hack2.Response -> IO Happstack.Response+hackRToServerPartR r = do+  body_bytestring <- fromEnumerator $ Hack2.unHackEnumerator $ Hack2.body r+  return $ +    Happstack.Response +      { rsCode      = Hack2.status r+      , rsHeaders   = httpToHeaders $ Hack2.headers r+      , rsFlags     = RsFlags {rsfContentLength = False}+      , rsBody      = body_bytestring+      , rsValidator = Nothing +      }  l2s :: L.ByteString -> S.ByteString l2s = S.concat . L.toChunks