Files
gf-core/src/server/ServeStaticFile.hs
hallgren 5e1f2c069f pgf-server HTTP mode: omit charset from ContentType for static files
When pfg-server servers a static file in HTTP mode, it is output as is, so
specifying charset="iso-8859-1" could be wrong. 

Note: the a charset can be specified with a meta tag in HTML files,
e.g. for files in UTF-8:

<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
2010-09-24 12:34:38 +00:00

26 lines
777 B
Haskell

module ServeStaticFile where
import System.FilePath
import System.Directory(doesDirectoryExist)
import Network.CGI(setHeader,outputFPS,liftIO)
import qualified Data.ByteString.Lazy.Char8 as BS
serveStaticFile path =
do b <- liftIO $ doesDirectoryExist path
let path' = if b then path </> "index.html" else path
serveStaticFile' path'
serveStaticFile' path =
do setHeader "Content-Type" (contentTypeFromExt (takeExtension path))
outputFPS =<< liftIO (BS.readFile path)
contentTypeFromExt ext =
case ext of
".html" -> "text/html"
".htm" -> "text/html"
".xml" -> "text/xml"
".txt" -> "text/plain"
".css" -> "text/css"
".js" -> "text/javascript"
".png" -> "image/png"
".jpg" -> "image/jpg"
_ -> "application/octet-stream"