summaryrefslogtreecommitdiff
path: root/src/server/FastCGIUtils.hs
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2011-08-22 15:34:44 +0000
committerhallgren <hallgren@chalmers.se>2011-08-22 15:34:44 +0000
commitd8d80693db7d18cd6ac84b87358b6e3d55be9fbc (patch)
tree310808acdf913cc0c0fdcd49e35278e787f5eb21 /src/server/FastCGIUtils.hs
parent36b9d55ed68154d4b93d052b499c091ac83b7a63 (diff)
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
Diffstat (limited to 'src/server/FastCGIUtils.hs')
-rw-r--r--src/server/FastCGIUtils.hs19
1 files changed, 14 insertions, 5 deletions
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."