mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
Added JSON-P support to fastcgi server.
This commit is contained in:
@@ -39,7 +39,7 @@ cgiMain pgf =
|
|||||||
"/translate" -> return (doTranslate pgf) `ap` getText `ap` getCat `ap` getFrom `ap` getTo
|
"/translate" -> return (doTranslate pgf) `ap` getText `ap` getCat `ap` getFrom `ap` getTo
|
||||||
"/grammar" -> return (doGrammar pgf) `ap` requestAcceptLanguage
|
"/grammar" -> return (doGrammar pgf) `ap` requestAcceptLanguage
|
||||||
_ -> throwCGIError 404 "Not Found" ["Resource not found: " ++ path]
|
_ -> throwCGIError 404 "Not Found" ["Resource not found: " ++ path]
|
||||||
outputJSON json
|
outputJSONP json
|
||||||
where
|
where
|
||||||
getText :: CGI String
|
getText :: CGI String
|
||||||
getText = liftM (maybe "" (urlDecodeUnicode . UTF8.decodeString)) $ getInput "input"
|
getText = liftM (maybe "" (urlDecodeUnicode . UTF8.decodeString)) $ getInput "input"
|
||||||
@@ -148,9 +148,14 @@ langCodeLanguage pgf code = listToMaybe [l | l <- PGF.languages pgf, PGF.languag
|
|||||||
|
|
||||||
-- * General CGI and JSON stuff
|
-- * General CGI and JSON stuff
|
||||||
|
|
||||||
outputJSON :: JSON a => a -> CGI CGIResult
|
outputJSONP :: JSON a => a -> CGI CGIResult
|
||||||
outputJSON x = do setHeader "Content-Type" "text/json; charset=utf-8"
|
outputJSONP x =
|
||||||
outputStrict $ UTF8.encodeString $ encode 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 :: String -> CGI CGIResult
|
||||||
outputStrict x | x == x = output x
|
outputStrict x | x == x = output x
|
||||||
|
|||||||
Reference in New Issue
Block a user