hack-handler-happstack 2009.5.19 → 2009.6.5
raw patch · 3 files changed
+23/−12 lines, 3 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Hack.Handler.Happstack: instance Default ServerConf
Files
- changelog.md +11/−0
- hack-handler-happstack.cabal +2/−2
- src/Hack/Handler/Happstack.hs +10/−10
changelog.md view
@@ -1,3 +1,14 @@+2009.6.5+--------++### Feature++* add default instance to ServerConf++### Fix++* pass arbitrary ab -n test, use bytestring char8.+ 2009.5.19 ---------
hack-handler-happstack.cabal view
@@ -1,5 +1,5 @@ Name: hack-handler-happstack-Version: 2009.5.19+Version: 2009.6.5 Build-type: Simple Synopsis: Hack Happstack server handler Description: Hack Happstack server handler@@ -15,7 +15,7 @@ library ghc-options: -Wall- build-depends: base, cgi, network, bytestring, data-default >= 0.2, hack >= 2009.5.19, happstack-server >= 0.2.1, containers, mtl+ build-depends: base >= 4.0 && < 5, cgi, network, bytestring, data-default >= 0.2, hack >= 2009.5.19, happstack-server >= 0.2.1, containers, mtl hs-source-dirs: src/ exposed-modules: Hack.Handler.Happstack
src/Hack/Handler/Happstack.hs view
@@ -12,25 +12,27 @@ import Control.Arrow ((>>>)) import Data.Default-import Control.Monad.Trans import Data.List import Data.Char import Data.Maybe+import Control.Monad.State+import Data.Default import qualified Data.Map as M-import qualified Data.ByteString as L-import qualified Data.ByteString.Internal as I+import qualified Data.ByteString.Char8 as S -- | we need this for 1. port 2. a bug in current Happstack. -- i.e. rqPeer will not give the corrent value for serverName and port data ServerConf = ServerConf { port :: Int, serverName :: String }+instance Default ServerConf where+ def = ServerConf { port = 3000, serverName = "localhost" } runWithConfig :: ServerConf -> Hack.Application -> IO () runWithConfig conf app = Happstack.simpleHTTP nullConf { H.port = port conf } $ myPart conf app run :: Hack.Application -> IO ()-run = runWithConfig $ ServerConf { port = 3000, serverName = "localhost" }+run = runWithConfig $ def myPart :: ServerConf -> Hack.Application -> ServerPart (Happstack.Response) myPart conf app = do@@ -68,8 +70,8 @@ toHttp = M.toList >>> map snd >>> map headerToPair headerToPair :: HeaderPair -> (String, String)-headerToPair (HeaderPair k v) = (translate_header $ b2s k, intercalate " " $ map b2s v)- where b2s x = map I.w2c $ L.unpack x+headerToPair (HeaderPair k v) = + (translate_header $ S.unpack k, intercalate " " $ map S.unpack v) toHappstackResponse :: Hack.Response -> Happstack.Response toHappstackResponse resp = Happstack.Response @@ -80,14 +82,12 @@ , rsValidator = Nothing } - convertHeaders :: [(String, String)] -> Happstack.Headers convertHeaders = map pairToHeader >>> M.fromList where - pairToHeader (k,v) = ((c2b $ map toLower k), HeaderPair (c2b k) [c2b v])- c2b x = L.pack $ map I.c2w x+ pairToHeader (k,v) = + ((S.pack $ map toLower k), HeaderPair (S.pack k) [S.pack v]) - -- happstack converts all request header to lowercase ... -- so we need to convert it back ...