pgf service: added a hook for external services

This is really reinventing CGI, people should learn how to write CGI scripts
instead...
TODO: better handling of temporary files
This commit is contained in:
hallgren
2011-08-22 15:34:44 +00:00
parent 3d20737e95
commit 3e2f768072
2 changed files with 43 additions and 6 deletions

View File

@@ -1,10 +1,11 @@
{-# LANGUAGE DeriveDataTypeable, CPP #-}
module FastCGIUtils (--initFastCGI, loopFastCGI,
throwCGIError, handleCGIErrors,
stderrToFile,
outputJSONP,
stderrToFile,logError,
outputJSONP,outputEncodedJSONP,
outputPNG,
outputHTML,
outputPlain,
splitBy) where
import Control.Concurrent
@@ -160,11 +161,14 @@ handleCGIErrors x = x `catchCGI` \e -> case fromException e of
-- * General CGI and JSON stuff
outputJSONP :: JSON a => a -> CGI CGIResult
outputJSONP x =
outputJSONP = outputEncodedJSONP . encode
outputEncodedJSONP :: String -> CGI CGIResult
outputEncodedJSONP json =
do mc <- getInput "jsonp"
let str = case mc of
Nothing -> encode x
Just c -> c ++ "(" ++ encode x ++ ")"
Nothing -> json
Just c -> c ++ "(" ++ json ++ ")"
setHeader "Content-Type" "text/javascript; charset=utf-8"
outputStrict $ UTF8.encodeString str
@@ -178,6 +182,11 @@ outputHTML x = do
setHeader "Content-Type" "text/html"
outputStrict $ UTF8.encodeString x
outputPlain :: String -> CGI CGIResult
outputPlain x = do
setHeader "Content-Type" "text/plain"
outputStrict $ UTF8.encodeString x
outputStrict :: String -> CGI CGIResult
outputStrict x | x == x = output x
| otherwise = fail "I am the pope."