diff options
| author | hallgren <hallgren@chalmers.se> | 2013-07-25 16:04:43 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2013-07-25 16:04:43 +0000 |
| commit | e07a74df01fdb5fc67513207b587f074f577e7d8 (patch) | |
| tree | 5113b70198e91579a8ebda843051e64a8fcbc36b /src/server | |
| parent | 0087456c7aefb0ac72a221cba66899ba795ba838 (diff) | |
Allow cross origin requests to GF cloud & PGF services
By adding a header
Access-Control-Allow-Origin: *
to the HTTP responses, web browsers are informed that it is OK to call the
services from web pages hosted on other sites.
This is apparently supported in most modern browsers, so it should no longer
be necessary to resort to JSONP.
See https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/FastCGIUtils.hs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/server/FastCGIUtils.hs b/src/server/FastCGIUtils.hs index 05aa29eac..6c93b2801 100644 --- a/src/server/FastCGIUtils.hs +++ b/src/server/FastCGIUtils.hs @@ -22,7 +22,8 @@ import System.Posix #endif --import Network.FastCGI -import Network.CGI +import Network.CGI(CGI,CGIResult,setHeader,output,outputFPS,outputError, + getInput,catchCGI,throwCGI) import Text.JSON import qualified Codec.Binary.UTF8.String as UTF8 (encodeString) @@ -153,9 +154,10 @@ throwCGIError :: Int -> String -> [String] -> CGI a throwCGIError c m t = throwCGI $ toException $ CGIError c m t handleCGIErrors :: CGI CGIResult -> CGI CGIResult -handleCGIErrors x = x `catchCGI` \e -> case fromException e of - Nothing -> throw e - Just (CGIError c m t) -> outputError c m t +handleCGIErrors x = + x `catchCGI` \e -> case fromException e of + Nothing -> throw e + Just (CGIError c m t) -> do setXO; outputError c m t -- * General CGI and JSON stuff @@ -174,11 +176,13 @@ outputEncodedJSONP json = outputPNG :: BS.ByteString -> CGI CGIResult outputPNG x = do setHeader "Content-Type" "image/png" + setXO outputFPS x outputBinary :: BS.ByteString -> CGI CGIResult outputBinary x = do setHeader "Content-Type" "application/binary" + setXO outputFPS x outputHTML :: String -> CGI CGIResult @@ -192,9 +196,12 @@ outputPlain x = do outputStrict $ UTF8.encodeString x outputStrict :: String -> CGI CGIResult -outputStrict x | x == x = output x +outputStrict x | x == x = do 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 + -- * General utilities splitBy :: (a -> Bool) -> [a] -> [[a]] |
