@@ -8,7 +8,7 @@ import Prelude hiding (log)
88import Network
99import Control.Monad (forever, mapM_)
1010import Control.Monad.Reader (ReaderT, runReaderT, ask, liftIO)
11−import System.IO (Handle, hClose, hGetLine, hPutStr, hPutStrLn, stderr)
11+import System.IO
1212import System.Directory (doesFileExist, doesDirectoryExist)
1313import Control.Concurrent (forkIO)
1414import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan)
@@ -83,9 +83,9 @@ createResponse request
8383 | otherwise = return $ createErrorResponse 501 "Not Implemented"
8484
8585-- | Create a simple error response.
86−createErrorResponse :: Int -- ^ Error code.
87− -> String -- ^ Error phrase.
88− -> Response -- ^ Result.
86+createErrorResponse :: Int -- ^ Error code.
87+ -> String -- ^ Error phrase.
88+ -> Response -- ^ Result.
8989createErrorResponse statusCode phrase = defaultResponse
9090 { responseStatusCode = statusCode
9191 , responsePhrase = phrase
@@ -109,9 +109,12 @@ createGetResponse request = do
109109 else uri
110110
111111 create200 = do
112+ h <- openFile fileName ReadMode
113+ contentLength <- hFileSize h
114+ hClose h
112115 body <- readFile fileName
113116 let headers =
114− [ ("Content-Length", show $ length body)
117+ [ ("Content-Length", show $ contentLength)
115118 ] ++ getMIMEHeader fileName
116119 return $ defaultResponse
117120 { responseStatusCode = 200