@@ -8,7 +8,8 @@ import Prelude hiding (log)
88import Control.Monad (forever)
99import Control.Monad.Reader (ReaderT, runReaderT, ask, liftIO)
1010import Network
11−import System.IO
11+import System.IO (stderr, Handle, IOMode(..), openFile, hFileSize, hClose)
12+import qualified System.IO.UTF8 as U
1213import System.Directory (doesFileExist, doesDirectoryExist)
1314import Control.Concurrent (forkIO)
1415import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan)
@@ -21,7 +22,7 @@ import Text.Hakyll.Regex
2122
2223-- | Function to log from a chan.
2324log :: Chan String -> IO ()
24−log logChan = forever (readChan logChan >>= hPutStrLn stderr)
25+log logChan = forever (readChan logChan >>= U.hPutStrLn stderr)
2526
2627-- | General server configuration.
2728data ServerConfig = ServerConfig { documentRoot :: FilePath
@@ -47,7 +48,7 @@ instance Show Request where
4748-- headers and body.
4849readRequest :: Handle -> Server Request
4950readRequest handle = do
50− requestLine <- liftIO $ hGetLine handle
51+ requestLine <- liftIO $ U.hGetLine handle
5152 let [method, uri, version] = map trim $ splitRegex " " requestLine
5253 return $ Request { requestMethod = method
5354 , requestURI = uri
@@ -147,7 +148,7 @@ getMIMEHeader fileName =
147148 result = lookup (takeExtension fileName) [ (".css", "text/css")
148149 , (".gif", "image/gif")
149150 , (".htm", "text/html")
150− , (".html", "text/html")
151+ , (".html", "text/html; charset=utf8")
151152 , (".jpeg", "image/jpeg")
152153 , (".jpg", "image/jpeg")
153154 , (".js", "text/javascript")
@@ -171,21 +172,21 @@ respond handle = do
171172 -- Send the response back to the handle.
172173 liftIO $ putResponse response
173174 where
174− putResponse response = do hPutStr handle $ intercalate " "
175+ putResponse response = do U.hPutStr handle $ intercalate " "
175176 [ responseVersion response
176177 , show $ responseStatusCode response
177178 , responsePhrase response
178179 ]
179− hPutStr handle "\r\n"
180+ U.hPutStr handle "\r\n"
180181 mapM_ putHeader
181182 (M.toList $ responseHeaders response)
182− hPutStr handle "\r\n"
183− hPutStr handle $ responseBody response
184− hPutStr handle "\r\n"
183+ U.hPutStr handle "\r\n"
184+ U.hPutStr handle $ responseBody response
185+ U.hPutStr handle "\r\n"
185186 hClose handle
186187
187188 putHeader (key, value) =
188− hPutStr handle $ key ++ ": " ++ value ++ "\r\n"
189+ U.hPutStr handle $ key ++ ": " ++ value ++ "\r\n"
189190
190191-- | Start a simple http server on the given 'PortNumber', serving the given
191192-- directory.