mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 13:09:33 -06:00
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">
26 lines
777 B
Haskell
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" |