Skip to content

Commit 8928a8a

Browse files
committed
Content type should be JSON by default when sending JSON.
This solves hub4j#350 a little differently.
1 parent 2b6f37a commit 8928a8a

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/main/java/org/kohsuke/github/Requester.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import static java.util.Arrays.asList;
6161
import java.util.logging.Level;
6262
import static java.util.logging.Level.*;
63+
import static org.apache.commons.lang.StringUtils.defaultString;
6364
import static org.kohsuke.github.GitHub.MAPPER;
6465

6566
/**
@@ -76,7 +77,7 @@ class Requester {
7677
* Request method.
7778
*/
7879
private String method = "POST";
79-
private String contentType = "application/x-www-form-urlencoded";
80+
private String contentType = null;
8081
private InputStream body;
8182

8283
/**
@@ -392,18 +393,19 @@ public String getResponseHeader(String header) {
392393
private void buildRequest() throws IOException {
393394
if (isMethodWithBody()) {
394395
uc.setDoOutput(true);
395-
uc.setRequestProperty("Content-type", contentType);
396396

397397
if (body == null) {
398+
uc.setRequestProperty("Content-type", defaultString(contentType,"application/json"));
398399
Map json = new HashMap();
399400
for (Entry e : args) {
400401
json.put(e.key, e.value);
401402
}
402403
MAPPER.writeValue(uc.getOutputStream(), json);
403404
} else {
405+
uc.setRequestProperty("Content-type", defaultString(contentType,"application/x-www-form-urlencoded"));
404406
try {
405407
byte[] bytes = new byte[32768];
406-
int read = 0;
408+
int read;
407409
while ((read = body.read(bytes)) != -1) {
408410
uc.getOutputStream().write(bytes, 0, read);
409411
}

0 commit comments

Comments
 (0)