hack-handler-simpleserver 0.0.0 → 0.0.1
raw patch · 2 files changed
+13/−14 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
Hack/Handler/SimpleServer.hs view
@@ -15,17 +15,16 @@ ( run ) where -import Prelude ( ($), (++), map, IO, String, null, return+import Prelude ( ($), map, IO, String, return , length, (==), fail, break, tail, Monad, Int- , fromIntegral, head, (>=), fmap, (.), uncurry, words, show- , Read, reads)+ , fromIntegral, head, (>=), (.), words, show+ , Read, reads, dropWhile, takeWhile, (/=)) import Hack import Data.Default import Data.ByteString.Lazy.Util (takeUntilBlank) import Data.Mime.Header (parseHeader, lookupHeader)-import Web.Encodings (decodeUrlPairs, decodeCookies, parsePost) import qualified Data.ByteString.Lazy as BS import qualified Data.ByteString.Lazy.UTF8 as BSLU@@ -66,8 +65,8 @@ hParseEnv :: Port -> Handle -> IO Env hParseEnv port conn = do content' <- BS.hGetContents conn- let (headers, body) = takeUntilBlank content'- parseEnv port headers body+ let (headers', body') = takeUntilBlank content'+ parseEnv port headers' body' safeRead :: Read a => a -> String -> a safeRead d s =@@ -77,7 +76,7 @@ -- | Parse a set of header lines and body into a 'Env'. parseEnv :: Monad m => Port -> [BS.ByteString] -> BS.ByteString -> m Env-parseEnv port lines' body = do+parseEnv port lines' body' = do let lines = map BSLU.toString lines' unless (length lines >= 2) $ fail "Invalid request (not enough lines)" (method', rpath', gets) <- parseFirst $ head lines@@ -90,15 +89,15 @@ unless (isJust host') $ fail "Invalid request (does not include host)" let host = fromJust host' let len = fromMaybe "0" $ lookupHeader "Content-Length" heads- let body' = BS.take (safeRead 0 len) body+ let body'' = BS.take (safeRead 0 len) body' return $ def { requestMethod = method , pathInfo = rpath- , queryString = gets- , serverName = host+ , queryString = dropWhile (== '?') gets+ , serverName = takeWhile (/= ':') host , serverPort = port , http = heads- , hackInput = body'+ , hackInput = body'' } parseFirst :: Monad m =>@@ -107,8 +106,8 @@ parseFirst s = do let pieces = words s unless (length pieces == 3) $ fail "Invalid request (bad first line)"- let [method, query, http] = pieces- unless (http == "HTTP/1.1") $+ let [method, query, http'] = pieces+ unless (http' == "HTTP/1.1") $ fail "Invalid request (only handle HTTP/1.1)" let (rpath, qstring) = break (== '?') query return (method, rpath, qstring)
hack-handler-simpleserver.cabal view
@@ -1,5 +1,5 @@ name: hack-handler-simpleserver-version: 0.0.0+version: 0.0.1 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>