summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbjorn <bjorn@bringert.net>2008-10-20 15:17:57 +0000
committerbjorn <bjorn@bringert.net>2008-10-20 15:17:57 +0000
commit6633ae71f1be152bffad04004570bb4c3d348a81 (patch)
treeb46aa9f343f215bd2a2754930b1599b134603d31 /src
parent41fb72ca6f2eb2299842cb86cf31aeb9e041046a (diff)
gf-server: move some general stuff to FastCGIUtils
Diffstat (limited to 'src')
-rw-r--r--src/server/FastCGIUtils.hs31
-rw-r--r--src/server/MainFastCGI.hs23
2 files changed, 30 insertions, 24 deletions
diff --git a/src/server/FastCGIUtils.hs b/src/server/FastCGIUtils.hs
index e9824d099..615915787 100644
--- a/src/server/FastCGIUtils.hs
+++ b/src/server/FastCGIUtils.hs
@@ -1,6 +1,8 @@
{-# LANGUAGE DeriveDataTypeable #-}
module FastCGIUtils (initFastCGI, loopFastCGI,
- throwCGIError, handleCGIErrors) where
+ throwCGIError, handleCGIErrors,
+ outputJSONP,
+ splitBy) where
import Control.Concurrent
import Control.Exception
@@ -18,6 +20,10 @@ import System.Time
import Network.FastCGI
+import Text.JSON
+import qualified Codec.Binary.UTF8.String as UTF8 (encodeString, decodeString)
+
+
initFastCGI :: IO ()
initFastCGI = installSignalHandlers
@@ -118,3 +124,26 @@ handleCGIErrors x = x `catchCGI` \e -> case e of
Nothing -> throw e
Just (CGIError c m t) -> outputError c m t
_ -> throw e
+
+-- * General CGI and JSON stuff
+
+outputJSONP :: JSON a => a -> CGI CGIResult
+outputJSONP x =
+ do mc <- getInput "jsonp"
+ let str = case mc of
+ Nothing -> encode x
+ Just c -> c ++ "(" ++ encode x ++ ")"
+ setHeader "Content-Type" "text/json; charset=utf-8"
+ outputStrict $ UTF8.encodeString str
+
+outputStrict :: String -> CGI CGIResult
+outputStrict x | x == x = output x
+ | otherwise = fail "I am the pope."
+
+-- * General utilities
+
+splitBy :: (a -> Bool) -> [a] -> [[a]]
+splitBy _ [] = [[]]
+splitBy f list = case break f list of
+ (first,[]) -> [first]
+ (first,_:rest) -> first : splitBy f rest \ No newline at end of file
diff --git a/src/server/MainFastCGI.hs b/src/server/MainFastCGI.hs
index 9734ab2f3..84fd3108e 100644
--- a/src/server/MainFastCGI.hs
+++ b/src/server/MainFastCGI.hs
@@ -154,26 +154,3 @@ selectLanguage pgf macc = case acceptable of
langCodeLanguage :: PGF -> String -> Maybe PGF.Language
langCodeLanguage pgf code = listToMaybe [l | l <- PGF.languages pgf, PGF.languageCode pgf l == Just code]
-
--- * General CGI and JSON stuff
-
-outputJSONP :: JSON a => a -> CGI CGIResult
-outputJSONP x =
- do mc <- getInput "jsonp"
- let str = case mc of
- Nothing -> encode x
- Just c -> c ++ "(" ++ encode x ++ ")"
- setHeader "Content-Type" "text/json; charset=utf-8"
- outputStrict $ UTF8.encodeString str
-
-outputStrict :: String -> CGI CGIResult
-outputStrict x | x == x = output x
- | otherwise = fail "I am the pope."
-
--- * General utilities
-
-splitBy :: (a -> Bool) -> [a] -> [[a]]
-splitBy _ [] = [[]]
-splitBy f list = case break f list of
- (first,[]) -> [first]
- (first,_:rest) -> first : splitBy f rest \ No newline at end of file