Skip to content

Commit

Permalink
Adds JSONP support. You need to set ERXRest.allowJSONP=true to get it…
Browse files Browse the repository at this point in the history
… to work.
  • Loading branch information
Pascal Robert committed Jul 14, 2012
1 parent 1f2e661 commit 9b6140e
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,22 @@ protected WOActionResults processActionResults(WOActionResults results) {
processedResults = response;
}
}
if (allowJSONP()) {
if (this.format().equals(ERXRestFormat.json())) {
String callbackMethodName = request().stringFormValueForKey("callback");
if (callbackMethodName != null) {
WOResponse response = results.generateResponse();
String content = response.contentString();
if (content != null) {
content = content.replaceAll("\n", "");
content = ERXStringUtilities.escapeJavascriptApostrophes(content);
}
response.setContent(callbackMethodName + "(" + content + ");");
response.setHeader("text/javascript", "Content-Type");
processedResults = response;
}
}
}
return processedResults;
}

Expand All @@ -1650,6 +1666,15 @@ protected boolean allowWindowNameCrossDomainTransport() {
return ERXProperties.booleanForKeyWithDefault("ERXRest.allowWindowNameCrossDomainTransport", false);
}

/**
* Returns whether or not JSONP (JSON with Padding) is allowed.
*
* @return whether or not JSONP (JSON with Padding) is allowed
*/
protected boolean allowJSONP() {
return ERXProperties.booleanForKeyWithDefault("ERXRest.allowJSONP", false);
}

/**
* Returns the allowed origin for cross-site requests. Set the property ERXRest.accessControlAllowOrigin=* to enable all origins.
*
Expand Down

0 comments on commit 9b6140e

Please sign in to comment.