From d8d80693db7d18cd6ac84b87358b6e3d55be9fbc Mon Sep 17 00:00:00 2001 From: hallgren Date: Mon, 22 Aug 2011 15:34:44 +0000 Subject: 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 --- src/server/FastCGIUtils.hs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/server/FastCGIUtils.hs') diff --git a/src/server/FastCGIUtils.hs b/src/server/FastCGIUtils.hs index f9e575df7..2abc66072 100644 --- a/src/server/FastCGIUtils.hs +++ b/src/server/FastCGIUtils.hs @@ -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." -- cgit v1.2.3