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/compiler | |
| 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/compiler')
| -rw-r--r-- | src/compiler/GFServer.hs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/compiler/GFServer.hs b/src/compiler/GFServer.hs index 4e794ae33..b45862aca 100644 --- a/src/compiler/GFServer.hs +++ b/src/compiler/GFServer.hs @@ -339,16 +339,16 @@ jsonp qs = json200' $ maybe id apply (lookup "jsonp" qs) apply f json = f++"("++json++")" -- * Standard HTTP responses -ok200 = Response 200 [plainUTF8,noCache] . encodeString -ok200' t = Response 200 [t] +ok200 = Response 200 [plainUTF8,noCache,xo] . encodeString +ok200' t = Response 200 [t,xo] json200 x = json200' id x json200' f = ok200' jsonUTF8 . encodeString . f . encode html200 = ok200' htmlUTF8 . encodeString -resp204 = Response 204 [] "" -- no content -resp400 msg = Response 400 [plain] $ "Bad request: "++msg++"\n" -resp404 path = Response 404 [plain] $ "Not found: "++path++"\n" -resp500 msg = Response 500 [plain] $ "Internal error: "++msg++"\n" -resp501 msg = Response 501 [plain] $ "Not implemented: "++msg++"\n" +resp204 = Response 204 [xo] "" -- no content +resp400 msg = Response 400 [plain,xo] $ "Bad request: "++msg++"\n" +resp404 path = Response 404 [plain,xo] $ "Not found: "++path++"\n" +resp500 msg = Response 500 [plain,xo] $ "Internal error: "++msg++"\n" +resp501 msg = Response 501 [plain,xo] $ "Not implemented: "++msg++"\n" instance Error Response where noMsg = resp500 "no message" @@ -360,6 +360,8 @@ plainUTF8 = ct "text/plain; charset=UTF-8" jsonUTF8 = ct "text/javascript; charset=UTF-8" htmlUTF8 = ct "text/html; charset=UTF-8" ct t = ("Content-Type",t) +xo = ("Access-Control-Allow-Origin","*") -- Allow cross origin requests + -- https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS contentTypeFromExt ext = case ext of @@ -441,7 +443,9 @@ utf8inputs q = [(decodeString k,(decodeString v,v))|(k,v)<-inputs q] decoded = mapSnd fst raw = mapSnd snd -inputs = decodeQuery +inputs ('?':q) = decodeQuery q +inputs q = decodeQuery q + {- -- Stay clear of queryToArgument, which uses unEscapeString, which had -- backward incompatible changes in network-2.4.1.1, see |
