Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhen Chen2016-11-22 01:15:15 +0000
committerZhen Chen2016-11-22 20:24:32 +0000
commitca2183a403b986d5ed2a2562b614a3dd4f36ffad (patch)
treef4741b989ada18d2ef0ad3ed3e66ade7bfe53187 /org.eclipse.jgit.http.apache
parent81f9c18433f9d53a64498b07c90c4fc73654d942 (diff)
downloadjgit-ca2183a403b986d5ed2a2562b614a3dd4f36ffad.tar.gz
jgit-ca2183a403b986d5ed2a2562b614a3dd4f36ffad.tar.xz
jgit-ca2183a403b986d5ed2a2562b614a3dd4f36ffad.zip
Fix content length in HttpClientConnection
Per the interface specification, the getContentLength method should return -1 if content length is unknown or greater than Integer.MAX_VALUE. For chunked transfer encoding, the content length is not included in the header, hence will cause a NullPointerException when trying to parse the content length header. Change-Id: Iaa36b5c146a8d654e364635fa0bd2d14129baf17 Signed-off-by: Zhen Chen <czhen@google.com>
Diffstat (limited to 'org.eclipse.jgit.http.apache')
-rw-r--r--org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/HttpClientConnection.java13
1 files changed, 11 insertions, 2 deletions
diff --git a/org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/HttpClientConnection.java b/org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/HttpClientConnection.java
index 5a53490eed..281154fb1a 100644
--- a/org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/HttpClientConnection.java
+++ b/org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/HttpClientConnection.java
@@ -323,8 +323,17 @@ public class HttpClientConnection implements HttpConnection {
}
public int getContentLength() {
- return Integer.parseInt(resp.getFirstHeader("content-length") //$NON-NLS-1$
- .getValue());
+ Header contentLength = resp.getFirstHeader("content-length"); //$NON-NLS-1$
+ if (contentLength == null) {
+ return -1;
+ }
+
+ try {
+ int l = Integer.parseInt(contentLength.getValue());
+ return l < 0 ? -1 : l;
+ } catch (NumberFormatException e) {
+ return -1;
+ }
}
public void setInstanceFollowRedirects(boolean followRedirects) {

Back to the top