--recordToString :: FastCGIRecord -> String
--recordToString record = map BSI.w2c $

--writeRecord :: Socket -> FastCGIRecord -> IO Bool 
--writeRecord sock record = do

getResponseFromCGI :: SvHost -> Request -> IO Response
getResponseFromCGI host request = do
    now <- getCurrentTime
    let filepath = svRoot (svConfig host) ++ rqURI request
    contents <- getDataFrom filepath
    let contents' = reverse . (dropWhile (=='\0')) . (drop 16) . reverse $ contents
    let (headers, body) = fromJust $ splitAtEmptyLine contents'
    return $ getResponse 1.1 200
        [ (Server, "hos")
        , (Date, httpDate now)
--        , (ContentType, fromJust $ getRequestHeader req ContentType)
        , (ContentLength, show $ length body)
        ] body
getResponseFromCGI :: SvHost -> Request -> IO Response
getResponseFromCGI host request = do
    now <- getCurrentTime
    let filepath = svRoot (svConfig host) ++ rqURI request
    contents <- getDataFrom filepath
    let contents' = reverse . (dropWhile (=='\0')) . (drop 16) . reverse $ contents
    let (headers, body) = fromJust $ splitAtEmptyLine contents'
    return $ getResponse 1.1 200
        [ (Server, "hos")
        , (Date, httpDate now)
--        , (ContentType, fromJust $ getRequestHeader req ContentType)
        , (ContentLength, show $ length body)
        ] body
getResponseFromCGI host request = do
    now <- getCurrentTime
    let filepath = svRoot (svConfig host) ++ rqURI request
    contents <- getDataFrom filepath
    let contents' = reverse . (dropWhile (=='\0')) . (drop 16) . reverse $ contents
    let (headers, body) = fromJust $ splitAtEmptyLine contents'
    return $ getResponse 1.1 200
        [ (Server, "hos")
        , (Date, httpDate now)
--        , (ContentType, fromJust $ getRequestHeader req ContentType)
        , (ContentLength, show $ length body)
        ] body