Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2012-04-11 23:35:08 -0400
committerKevin Sawicki2012-04-11 23:35:08 -0400
commit7bb8452cb4d2e97a4483f141bea2fa599a0e4b1d (patch)
treea197d2e6c1cc0f37e4b02b30a5abb723012944c7
parent98efbff146597d3a3e7b28bcaee673b5de9bce93 (diff)
downloadegit-github-7bb8452cb4d2e97a4483f141bea2fa599a0e4b1d.tar.gz
egit-github-7bb8452cb4d2e97a4483f141bea2fa599a0e4b1d.tar.xz
egit-github-7bb8452cb4d2e97a4483f141bea2fa599a0e4b1d.zip
Always set content length on PUT/POST/DELETE requests
This prevents a 411 Length Required exception from being thrown on requests where no body is sent Change-Id: I663e5c55dd43a0f54c725e1479584b01f2edf911
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java31
1 files changed, 16 insertions, 15 deletions
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java
index b82fd33f..cdcd3a3e 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java
@@ -560,23 +560,25 @@ public class GitHubClient {
protected void sendParams(HttpURLConnection request, Object params)
throws IOException {
request.setDoOutput(true);
- request.setRequestProperty(HEADER_CONTENT_TYPE, CONTENT_TYPE_JSON
- + "; charset=" + CHARSET_UTF8); //$NON-NLS-1$
- byte[] data = toJson(params).getBytes(CHARSET_UTF8);
- request.setFixedLengthStreamingMode(data.length);
- BufferedOutputStream output = new BufferedOutputStream(
- request.getOutputStream(), bufferSize);
- try {
- output.write(data);
- } finally {
- output.close();
- }
+ if (params != null) {
+ request.setRequestProperty(HEADER_CONTENT_TYPE, CONTENT_TYPE_JSON
+ + "; charset=" + CHARSET_UTF8); //$NON-NLS-1$
+ byte[] data = toJson(params).getBytes(CHARSET_UTF8);
+ request.setFixedLengthStreamingMode(data.length);
+ BufferedOutputStream output = new BufferedOutputStream(
+ request.getOutputStream(), bufferSize);
+ try {
+ output.write(data);
+ } finally {
+ output.close();
+ }
+ } else
+ request.setFixedLengthStreamingMode(0);
}
private <V> V sendJson(final HttpURLConnection request,
final Object params, final Type type) throws IOException {
- if (params != null)
- sendParams(request, params);
+ sendParams(request, params);
final int code = request.getResponseCode();
if (isOk(code))
if (type != null)
@@ -693,8 +695,7 @@ public class GitHubClient {
public void delete(final String uri, final Object params)
throws IOException {
HttpURLConnection request = createDelete(uri);
- if (params != null)
- sendParams(request, params);
+ sendParams(request, params);
final int code = request.getResponseCode();
if (!isEmpty(code))
throw new RequestException(parseError(getStream(request)), code);

Back to the top