diff options
| author | hallgren <hallgren@chalmers.se> | 2013-07-29 16:05:54 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2013-07-29 16:05:54 +0000 |
| commit | 27da46a79d3d465f5bcdfe8d2ac9d7614273e9ab (patch) | |
| tree | bb23c9e98e3b60c0556a53246edcab6a9a285ec2 /src/server/FastCGIUtils.hs | |
| parent | ecfcaa5395b40b1b090866b9f482277e983085a2 (diff) | |
Cloud & PGF service: use Content-Type application/json for JSON output
This is in accordance with RFC 4627. http://tools.ietf.org/html/rfc4627
Use application/javascript for JSONP output.
Diffstat (limited to 'src/server/FastCGIUtils.hs')
| -rw-r--r-- | src/server/FastCGIUtils.hs | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/server/FastCGIUtils.hs b/src/server/FastCGIUtils.hs index 6c93b2801..e65987b6d 100644 --- a/src/server/FastCGIUtils.hs +++ b/src/server/FastCGIUtils.hs @@ -167,11 +167,11 @@ outputJSONP = outputEncodedJSONP . encode outputEncodedJSONP :: String -> CGI CGIResult outputEncodedJSONP json = do mc <- getInput "jsonp" - let str = case mc of - Nothing -> json - Just c -> c ++ "(" ++ json ++ ")" - setHeader "Content-Type" "text/javascript; charset=utf-8" - outputStrict $ UTF8.encodeString str + let (ty,str) = case mc of + Nothing -> ("json",json) + Just c -> ("javascript",c ++ "(" ++ json ++ ")") + ct = "application/"++ty++"; charset=utf-8" + outputStrict ct $ UTF8.encodeString str outputPNG :: BS.ByteString -> CGI CGIResult outputPNG x = do @@ -186,18 +186,16 @@ outputBinary x = do outputFPS x outputHTML :: String -> CGI CGIResult -outputHTML x = do - setHeader "Content-Type" "text/html; charset=utf-8" - outputStrict $ UTF8.encodeString x +outputHTML = outputStrict "text/html; charset=utf-8" . UTF8.encodeString outputPlain :: String -> CGI CGIResult -outputPlain x = do - setHeader "Content-Type" "text/plain; charset=utf-8" - outputStrict $ UTF8.encodeString x +outputPlain = outputStrict "text/plain; charset=utf-8" . UTF8.encodeString -outputStrict :: String -> CGI CGIResult -outputStrict x | x == x = do setXO ; output x - | otherwise = fail "I am the pope." +outputStrict :: String -> String -> CGI CGIResult +outputStrict ct x | x == x = do setHeader "Content-Type" ct + setXO + output x + | otherwise = fail "I am the pope." setXO = setHeader "Access-Control-Allow-Origin" "*" -- https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS |
