Skip to content

Commit

Permalink
Merge pull request jenkinsci#239 from AtkinsChang/master
Browse files Browse the repository at this point in the history
Fix log and accepted content type
  • Loading branch information
DavidTanner committed Dec 22, 2015
2 parents afc0789 + a53df95 commit f4b5999
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,37 @@ public void doIndex(StaplerRequest req, StaplerResponse resp) {
String payload = null;
String body = null;

if ("application/json".equals(type)) {
if (type.toLowerCase().startsWith("application/json")) {
body = extractRequestBody(req);
if (body == null) {
logger.log(Level.SEVERE, "Can't get request body for application/json.");
resp.setStatus(StaplerResponse.SC_BAD_REQUEST);
return;
}
payload = body;
} else if ("application/x-www-form-urlencoded".equals(type)) {
} else if (type.toLowerCase().startsWith("application/x-www-form-urlencoded")) {
body = extractRequestBody(req);
if (body == null || body.length() <= 8) {
logger.log(Level.SEVERE, "Request doesn't contain payload. "
+ "You're sending url encoded request, so you should pass github payload through 'payload' request parameter");
resp.setStatus(StaplerResponse.SC_BAD_REQUEST);
return;
}
try {
String encoding = req.getCharacterEncoding();
payload = URLDecoder.decode(body.substring(8), encoding != null ? encoding : "UTF-8");
} catch (UnsupportedEncodingException e) {
logger.log(Level.SEVERE, "Error while trying to decode the payload");
resp.setStatus(StaplerResponse.SC_BAD_REQUEST);
return;
}
}

if (payload == null) {
logger.log(Level.SEVERE, "Payload is null, maybe content type '{0}' is not supported by this plugin. "
logger.log(Level.SEVERE, "Payload is null, maybe content type ''{0}'' is not supported by this plugin. "
+ "Please use 'application/json' or 'application/x-www-form-urlencoded'",
new Object[] { type });
resp.setStatus(StaplerResponse.SC_UNSUPPORTED_MEDIA_TYPE);
return;
}

Expand Down

0 comments on commit f4b5999

Please sign in to comment.