From 673ed68b8fd41c9420d353e6efd11d5405e53360 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Mon, 18 Jan 2010 09:11:43 +0100 Subject: Added UTF8 where nessecary. --- src/Network/Hakyll/SimpleServer.hs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/Network/Hakyll/SimpleServer.hs') diff --git a/src/Network/Hakyll/SimpleServer.hs b/src/Network/Hakyll/SimpleServer.hs index e26924b..fbce349 100644 --- a/src/Network/Hakyll/SimpleServer.hs +++ b/src/Network/Hakyll/SimpleServer.hs @@ -8,7 +8,8 @@ import Prelude hiding (log) import Control.Monad (forever) import Control.Monad.Reader (ReaderT, runReaderT, ask, liftIO) import Network -import System.IO +import System.IO (stderr, Handle, IOMode(..), openFile, hFileSize, hClose) +import qualified System.IO.UTF8 as U import System.Directory (doesFileExist, doesDirectoryExist) import Control.Concurrent (forkIO) import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan) @@ -21,7 +22,7 @@ import Text.Hakyll.Regex -- | Function to log from a chan. log :: Chan String -> IO () -log logChan = forever (readChan logChan >>= hPutStrLn stderr) +log logChan = forever (readChan logChan >>= U.hPutStrLn stderr) -- | General server configuration. data ServerConfig = ServerConfig { documentRoot :: FilePath @@ -47,7 +48,7 @@ instance Show Request where -- headers and body. readRequest :: Handle -> Server Request readRequest handle = do - requestLine <- liftIO $ hGetLine handle + requestLine <- liftIO $ U.hGetLine handle let [method, uri, version] = map trim $ splitRegex " " requestLine return $ Request { requestMethod = method , requestURI = uri @@ -147,7 +148,7 @@ getMIMEHeader fileName = result = lookup (takeExtension fileName) [ (".css", "text/css") , (".gif", "image/gif") , (".htm", "text/html") - , (".html", "text/html") + , (".html", "text/html; charset=utf8") , (".jpeg", "image/jpeg") , (".jpg", "image/jpeg") , (".js", "text/javascript") @@ -171,21 +172,21 @@ respond handle = do -- Send the response back to the handle. liftIO $ putResponse response where - putResponse response = do hPutStr handle $ intercalate " " + putResponse response = do U.hPutStr handle $ intercalate " " [ responseVersion response , show $ responseStatusCode response , responsePhrase response ] - hPutStr handle "\r\n" + U.hPutStr handle "\r\n" mapM_ putHeader (M.toList $ responseHeaders response) - hPutStr handle "\r\n" - hPutStr handle $ responseBody response - hPutStr handle "\r\n" + U.hPutStr handle "\r\n" + U.hPutStr handle $ responseBody response + U.hPutStr handle "\r\n" hClose handle putHeader (key, value) = - hPutStr handle $ key ++ ": " ++ value ++ "\r\n" + U.hPutStr handle $ key ++ ": " ++ value ++ "\r\n" -- | Start a simple http server on the given 'PortNumber', serving the given -- directory. -- cgit v1.2.3