Skip to content

Commit

Permalink
Merge pull request #200 from lanwen/lost_body_write
Browse files Browse the repository at this point in the history
fix for unused json map when method with body, but body is null
  • Loading branch information
kohsuke committed Jun 15, 2015
2 parents 9a4eee4 + 931ed7a commit dd3e739
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/org/kohsuke/github/Requester.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

/**
Expand All @@ -61,6 +62,8 @@
* @author Kohsuke Kawaguchi
*/
class Requester {
private static final List<String> METHODS_WITHOUT_BODY = asList("GET", "DELETE");

private final GitHub root;
private final List<Entry> args = new ArrayList<Entry>();
private final Map<String,String> headers = new LinkedHashMap<String, String>();
Expand Down Expand Up @@ -208,7 +211,7 @@ public <T> T to(String tailApiUrl, Class<T> type, String method) throws IOExcept

private <T> T _to(String tailApiUrl, Class<T> 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 ? '?' : '&');
Expand Down Expand Up @@ -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];
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit dd3e739

Please sign in to comment.