Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8928a8a

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

File tree

Expand file treeCollapse file tree

1 file changed

+5
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-3
lines changed

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/Requester.java
+5-3Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.