From 53d9ba21932873eafe82e395077378b05152d311 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Mon, 11 Jan 2010 18:53:36 +0100 Subject: Efficient file size. --- src/Network/Hakyll/SimpleServer.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Network/Hakyll/SimpleServer.hs b/src/Network/Hakyll/SimpleServer.hs index 38f037a..4baa466 100644 --- a/src/Network/Hakyll/SimpleServer.hs +++ b/src/Network/Hakyll/SimpleServer.hs @@ -8,7 +8,7 @@ import Prelude hiding (log) import Network import Control.Monad (forever, mapM_) import Control.Monad.Reader (ReaderT, runReaderT, ask, liftIO) -import System.IO (Handle, hClose, hGetLine, hPutStr, hPutStrLn, stderr) +import System.IO import System.Directory (doesFileExist, doesDirectoryExist) import Control.Concurrent (forkIO) import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan) @@ -83,9 +83,9 @@ createResponse request | otherwise = return $ createErrorResponse 501 "Not Implemented" -- | Create a simple error response. -createErrorResponse :: Int -- ^ Error code. - -> String -- ^ Error phrase. - -> Response -- ^ Result. +createErrorResponse :: Int -- ^ Error code. + -> String -- ^ Error phrase. + -> Response -- ^ Result. createErrorResponse statusCode phrase = defaultResponse { responseStatusCode = statusCode , responsePhrase = phrase @@ -109,9 +109,12 @@ createGetResponse request = do else uri create200 = do + h <- openFile fileName ReadMode + contentLength <- hFileSize h + hClose h body <- readFile fileName let headers = - [ ("Content-Length", show $ length body) + [ ("Content-Length", show $ contentLength) ] ++ getMIMEHeader fileName return $ defaultResponse { responseStatusCode = 200 -- cgit v1.2.3