@@ -29,6 +29,10 @@ import Blaze.ByteString.Builder.Enumerator (builderToByteString)
2929import Control.Monad.IO.Class (liftIO)
3030import Data.ByteString.Lazy.Internal (defaultChunkSize)
3131import System.IO (Handle)
32+import Network.HTTP.Types (Status (..))
33+import qualified Network.HTTP.Types as H
34+import Data.Ascii (ciToByteString)
35+import qualified Data.Ascii as A
3236
3337safeRead :: Read a => a -> String -> a
3438safeRead d s =
@@ -94,16 +98,18 @@ run'' vars inputH outputH xsendfile app = do
9498 a:_ -> addrAddress a
9599 [] -> error $ "Invalid REMOTE_ADDR or REMOTE_HOST: " ++ remoteHost'
96100 let env = Request
97− { requestMethod = rmethod
98− , pathInfo = B.pack pinfo
99− , queryString = B.pack qstring
101+ { requestMethod = A.unsafeFromByteString rmethod
102+ , rawPathInfo = B.pack pinfo
103+ , pathInfo = H.decodePathSegments $ B.pack pinfo
104+ , rawQueryString = B.pack qstring
105+ , queryString = H.parseQuery $ B.pack qstring
100106 , serverName = B.pack servername
101107 , serverPort = serverport
102− , requestHeaders = map (cleanupVarName *** B.pack) vars
108+ , requestHeaders = map (cleanupVarName *** A.unsafeFromString) vars
103109 , isSecure = isSecure'
104110 , errorHandler = System.IO.hPutStr System.IO.stderr
105111 , remoteHost = addr
106− , httpVersion = "1.1" -- FIXME
112+ , httpVersion = H.http11 -- FIXME
107113 }
108114 -- FIXME worry about exception?
109115 res <- run_ $ inputH contentLength $$ app env
@@ -117,9 +123,9 @@ run'' vars inputH outputH xsendfile app = do
117123 status (Status i m) = (fromByteString "Status", mconcat
118124 [ fromString $ show i
119125 , fromChar ' '
120− , fromByteString m
126+ , fromByteString $ A.toByteString m
121127 ])
122− header' (x, y) = (fromByteString $ ciOriginal x, fromByteString y)
128+ header' (x, y) = (fromByteString $ ciToByteString x, fromByteString $ A.toByteString y)
123129 header (x, y) = mconcat
124130 [ x
125131 , fromByteString ": "
@@ -143,7 +149,7 @@ run'' vars inputH outputH xsendfile app = do
143149 Nothing -> ("Content-Type", "text/html; charset=utf-8") : h
144150 Just _ -> h
145151
146−cleanupVarName :: String -> RequestHeader
152+cleanupVarName :: String -> A.CIAscii
147153cleanupVarName ('H':'T':'T':'P':'_':a:as) =
148154 String.fromString $ a : helper' as
149155 where