summaryrefslogtreecommitdiff
path: root/src/server/ServeStaticFile.hs
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2010-09-01 14:08:52 +0000
committerhallgren <hallgren@chalmers.se>2010-09-01 14:08:52 +0000
commitac23280320313b0e470c8de6d49415e93d3c9d97 (patch)
tree420ae6a2caf9bdd04016f772d47e12d4c6f96bb8 /src/server/ServeStaticFile.hs
parent31ee0bc804d93cf48b03895f05c03d0673383abc (diff)
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.)
Diffstat (limited to 'src/server/ServeStaticFile.hs')
-rw-r--r--src/server/ServeStaticFile.hs20
1 files changed, 20 insertions, 0 deletions
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