Permalink
Browse files

almost there

  • Loading branch information...
1 parent 9925427 commit 8f40731d3c873975cc3678e28205e8c996cc379f Chris Eidhof committed Apr 18, 2009
Showing with 13 additions and 3 deletions.
  1. +13 −3 FastCGI.hs
View
@@ -11,7 +11,9 @@ import qualified Data.Map as M
import Network.URI
import Control.Applicative
import qualified Data.ByteString.Lazy as BS
+import qualified Data.ByteString.UTF8 as UBS
import Data.List (isPrefixOf)
+import Data.Char (toLower)
numThreads :: Int
numThreads = 10
@@ -54,18 +56,26 @@ cgiMethod :: CGIRequest -> Method
cgiMethod x = withDef GET $ (x ? "HTTP_METHOD") >>= maybeRead
cgiPaths = split '/' . str "SCRIPT_NAME"
cgiQuery x = '?':(str "QUERY_STRING" x)
-cgiInputs :: CGI [(String, Input)]
cgiInputs = getInputNames >>= mapM toHappstackInput
cgiCookies = map cookieWithName . either (const []) id . parseCookies . str "HTTP_COOKIE"
cgiVersion = parseProtocol . str "SERVER_PROTOCOL"
-cgiHeaders = map toHeader . filter (isPrefixOf "HTTP" . fst) . M.toList . cgiVars
+cgiHeaders :: CGIRequest -> Headers
+cgiHeaders = M.mapKeys (UBS.fromString . map toLower)
+ . M.mapWithKey toHeaderPair
+ . M.mapKeys (drop (length httpStart))
+ . filterKey (isPrefixOf httpStart)
+ . cgiVars
cgiBody rq = undefined
cgiPeer rq = undefined
-toHeader = undefined
+httpStart = "HTTP_"
+
+toHeaderPair k v = HeaderPair (UBS.fromString k) [UBS.fromString v]
cookieWithName x = (H.cookieName x, x)
+filterKey f = M.filterWithKey (\x y -> f x)
+
parseProtocol "HTTP/0.9" = Version 0 9
parseProtocol "HTTP/1.0" = Version 1 0
parseProtocol "HTTP/1.1" = Version 1 1

0 comments on commit 8f40731

Please sign in to comment.