From ac23280320313b0e470c8de6d49415e93d3c9d97 Mon Sep 17 00:00:00 2001 From: hallgren Date: Wed, 1 Sep 2010 14:08:52 +0000 Subject: Standalone HTTP version of pgf-server pgf-server can now act as a standalone HTTP server. To activate this mode, start it with pfg-server http to use the default port number (41296), or give an explicit port number, e.g., pgf-server http 8080 The HTTP server serves PGF files in the same way as the old FastCGI interface. In addition, it also serves static files. The document root for static files is the www subdirectory of the current directory where pgf-server is started. In spite of these addition, backwards compatibility is maintaned. The old FastCGI interface continues to work as before. (It is activated when pgf-server is started without arguments.) --- src/server/ServeStaticFile.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/server/ServeStaticFile.hs (limited to 'src/server/ServeStaticFile.hs') diff --git a/src/server/ServeStaticFile.hs b/src/server/ServeStaticFile.hs new file mode 100644 index 000000000..f2bbc3e81 --- /dev/null +++ b/src/server/ServeStaticFile.hs @@ -0,0 +1,20 @@ +module ServeStaticFile where +import System.FilePath +import Network.CGI(setHeader,outputFPS,liftIO) +import qualified Data.ByteString.Lazy.Char8 as BS + +serveStaticFile path = + do setHeader "Content-Type" (contentTypeFromExt (takeExtension path)) + outputFPS =<< liftIO (BS.readFile path) + +contentTypeFromExt ext = + case ext of + ".html" -> "text/html; charset=\"iso8859-1\"" + ".htm" -> "text/html; charset=\"iso8859-1\"" + ".xml" -> "text/xml; charset=\"iso8859-1\"" + ".txt" -> "text/plain; charset=\"iso8859-1\"" + ".css" -> "text/css; charset=\"iso8859-1\"" + ".js" -> "text/javascript; charset=\"iso8859-1\"" + ".png" -> "image/png" + ".jpg" -> "image/jpg" + _ -> "application/octet-stream" \ No newline at end of file -- cgit v1.2.3