diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-01-11 18:53:36 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-01-11 18:53:36 +0100 |
commit | 53d9ba21932873eafe82e395077378b05152d311 (patch) | |
tree | 68cf8ca650b560b66a5753017935947bdd1d681e /src/Network | |
parent | 243062f126e36c3f3b3a80375faacdd1178ee5aa (diff) | |
download | hakyll-53d9ba21932873eafe82e395077378b05152d311.tar.gz |
Efficient file size.
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/Hakyll/SimpleServer.hs | 13 |
1 files changed, 8 insertions, 5 deletions
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 |