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.)
This commit is contained in:
hallgren
2010-09-01 14:08:52 +00:00
parent 31ee0bc804
commit ac23280320
4 changed files with 114 additions and 15 deletions

View File

@@ -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"