From 861fd55d06e1ad4250d36f34a388747d5dcb833c Mon Sep 17 00:00:00 2001 From: MerkushevKirill Date: Mon, 15 Jun 2015 17:57:16 +0300 Subject: [PATCH 1/2] fix for unused json map when method with body, but body is null fixes regression from b976e0ef4ef70f26b8d75a1a847b251f8c895e62 --- src/main/java/org/kohsuke/github/Requester.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index 253936c00a..f852e3b10d 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -53,6 +53,7 @@ import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; +import static java.util.Arrays.asList; import static org.kohsuke.github.GitHub.*; /** @@ -61,6 +62,8 @@ * @author Kohsuke Kawaguchi */ class Requester { + private static final List METHODS_WITHOUT_BODY = asList("GET", "DELETE"); + private final GitHub root; private final List args = new ArrayList(); private final Map headers = new LinkedHashMap(); @@ -296,6 +299,7 @@ private void buildRequest() throws IOException { for (Entry e : args) { json.put(e.key, e.value); } + MAPPER.writeValue(uc.getOutputStream(), json); } else { try { byte[] bytes = new byte[32768]; @@ -311,9 +315,7 @@ private void buildRequest() throws IOException { } private boolean isMethodWithBody() { - if (method.equals("GET")) return false; - if (method.equals("DELETE")) return false; - return true; + return !METHODS_WITHOUT_BODY.contains(method); } /** From 931ed7adac459e79c9b11843b5caad18753022e7 Mon Sep 17 00:00:00 2001 From: MerkushevKirill Date: Mon, 15 Jun 2015 18:14:58 +0300 Subject: [PATCH 2/2] don't ignore args when method without body in case of GET or DELETE request --- src/main/java/org/kohsuke/github/Requester.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index f852e3b10d..281426dd3e 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -211,7 +211,7 @@ public T to(String tailApiUrl, Class type, String method) throws IOExcept private T _to(String tailApiUrl, Class type, T instance) throws IOException { while (true) {// loop while API rate limit is hit - if (method.equals("GET") && !args.isEmpty()) { + if (METHODS_WITHOUT_BODY.contains(method) && !args.isEmpty()) { StringBuilder qs=new StringBuilder(); for (Entry arg : args) { qs.append(qs.length()==0 ? '?' : '&');