Skip to content
Permalink
Browse files
[JENKINS-17374 JENKINS-18116] Don't set gzip header for error
  • Loading branch information
daniel-beck committed May 31, 2014
1 parent 67dd49a commit 0a241aafdbdf3ad15d34efa3077658c5770b9195
Showing with 17 additions and 8 deletions.
  1. +17 −8 core/src/main/java/hudson/model/Api.java
@@ -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;
}

@@ -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.
*/

0 comments on commit 0a241aa

Please sign in to comment.