Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-17374 JENKINS-18116] Don't set gzip header for error
  • Loading branch information
daniel-beck committed May 31, 2014
1 parent 67dd49a commit 0a241aa
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions core/src/main/java/hudson/model/Api.java
Expand Up @@ -154,16 +154,21 @@ public void doXml(StaplerRequest req, StaplerResponse rsp,
throw new IOException("Failed to do XPath/wrapper handling. Turn on FINER logging to view XML.",e);
}


if (isSimpleOutput(result) && !permit(req)) {
// simple output prohibited
rsp.sendError(HttpURLConnection.HTTP_FORBIDDEN, "primitive XPath result sets forbidden; implement jenkins.security.SecureRequester");
return;
}

// switch to gzipped output
OutputStream o = rsp.getCompressedOutputStream(req);
try {
if (result instanceof CharacterData || result instanceof String || result instanceof Number || result instanceof Boolean) {
if (permit(req)) {
rsp.setContentType("text/plain;charset=UTF-8");
String text = result instanceof CharacterData ? ((CharacterData) result).getText() : result.toString();
o.write(text.getBytes("UTF-8"));
} else {
rsp.sendError(HttpURLConnection.HTTP_FORBIDDEN, "primitive XPath result sets forbidden; implement jenkins.security.SecureRequester");
}
if (isSimpleOutput(result)) {
// simple output allowed
rsp.setContentType("text/plain;charset=UTF-8");
String text = result instanceof CharacterData ? ((CharacterData) result).getText() : result.toString();
o.write(text.getBytes("UTF-8"));
return;
}

Expand All @@ -175,6 +180,10 @@ public void doXml(StaplerRequest req, StaplerResponse rsp,
}
}

private boolean isSimpleOutput(Object result) {
return result instanceof CharacterData || result instanceof String || result instanceof Number || result instanceof Boolean;
}

/**
* Generate schema.
*/
Expand Down

0 comments on commit 0a241aa

Please sign in to comment.