summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2013-05-14 19:34:38 (EDT)
committer Steffen Pingel2013-05-17 01:23:38 (EDT)
commit020e136d32940b7847ee0aef89d2269c5db92d14 (patch)
treed0dc1f80fcfc5552cab05983d6ef5319c7724447
parentdbe2bc25248b1ab238f3ccb6baac5c33c13ae3f8 (diff)
downloadorg.eclipse.mylyn.commons-020e136d32940b7847ee0aef89d2269c5db92d14.zip
org.eclipse.mylyn.commons-020e136d32940b7847ee0aef89d2269c5db92d14.tar.gz
org.eclipse.mylyn.commons-020e136d32940b7847ee0aef89d2269c5db92d14.tar.bz2
408044: connection is not released if gzip header is invalidrefs/changes/98/12798/2
Change-Id: I2ba9588ee82f26dd4d258ebdc46e70e0ee86bb92 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=408044
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java6
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/HttpUtilTest.java25
2 files changed, 30 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java
index dd79ed5..0b87004 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java
+++ b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java
@@ -347,7 +347,11 @@ public class HttpUtil {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
- // ignore
+ // if construction of the stream fails the connection has to be aborted to be released
+ try {
+ ((HttpUriRequest) request).abort();
+ } catch (UnsupportedOperationException e2) {
+ }
} catch (NullPointerException e) {
// XXX work-around for bug 368830
}
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/HttpUtilTest.java b/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/HttpUtilTest.java
index c5413e2..578e156 100644
--- a/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/HttpUtilTest.java
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/HttpUtilTest.java
@@ -18,6 +18,7 @@ import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.impl.client.ContentEncodingHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.eclipse.core.runtime.AssertionFailedException;
@@ -25,6 +26,7 @@ import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation;
import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials;
import org.eclipse.mylyn.commons.repositories.http.core.HttpUtil;
import org.eclipse.mylyn.commons.sdk.util.TestProxy;
+import org.eclipse.mylyn.commons.sdk.util.TestProxy.Message;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -109,4 +111,27 @@ public class HttpUtilTest {
HttpUtil.configureProxy(client, null);
}
+ @Test
+ public void testGetEmptyGzipResponse() throws Exception {
+ client = new ContentEncodingHttpClient() {
+ @Override
+ protected ClientConnectionManager createClientConnectionManager() {
+ return connectionManager;
+ }
+ };
+
+ Message message = new Message("HTTP/1.1 200 OK");
+ message.headers.add("Content-Length: 0");
+ message.headers.add("Content-Encoding: gzip");
+ message.headers.add("Connection: close");
+
+ testProxy.addResponse(message);
+ HttpRequestBase request = new HttpGet(testProxy.getUrl());
+
+ HttpUtil.configureClient(client, null);
+ HttpResponse response = HttpUtil.execute(client, null, request, null);
+ assertEquals(1, connectionManager.getConnectionsInPool());
+ HttpUtil.release(request, response, null);
+ assertEquals(0, connectionManager.getConnectionsInPool());
+ }
}