diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/AbstractHttpConnection.java b/jetty-client/src/main/java/org/eclipse/jetty/client/AbstractHttpConnection.java index 00571cad0b0..a032b38b17b 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/AbstractHttpConnection.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/AbstractHttpConnection.java @@ -179,7 +179,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection implemen _generator.setVersion(_exchange.getVersion()); String method=_exchange.getMethod(); - String uri = _exchange.getURI(); + String uri = _exchange.getRequestURI(); if (_destination.isProxied() && !HttpMethods.CONNECT.equals(method) && uri.startsWith("/")) { boolean secure = _destination.isSecure(); @@ -394,7 +394,11 @@ public abstract class AbstractHttpConnection extends AbstractConnection implemen } } - _endp.close(); + if (_endp.isOpen()) + { + _endp.close(); + _destination.returnConnection(this, true); + } } public void setIdleTimeout() diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/AbstractHttpExchangeCancelTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/AbstractHttpExchangeCancelTest.java index 923d6867664..c65525583d8 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/AbstractHttpExchangeCancelTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/AbstractHttpExchangeCancelTest.java @@ -14,15 +14,8 @@ package org.eclipse.jetty.client; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - import java.io.IOException; import java.net.SocketTimeoutException; - import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; @@ -36,18 +29,22 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.StdErrLog; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + /** */ public abstract class AbstractHttpExchangeCancelTest { - private static final Logger LOG = Log.getLogger(AbstractHttpExchangeCancelTest.TestHttpExchange.class); - private Server server; private Connector connector; @@ -362,7 +359,7 @@ public abstract class AbstractHttpExchangeCancelTest int status = exchange.waitForDone(); long end = System.currentTimeMillis(); - + assertTrue(HttpExchange.STATUS_EXPIRED==status||HttpExchange.STATUS_EXCEPTED==status); assertFalse(exchange.isResponseCompleted()); assertTrue(end-start<4000); @@ -371,6 +368,26 @@ public abstract class AbstractHttpExchangeCancelTest assertFalse(exchange.isAssociated()); } + @Test + public void testHttpExchangeCancelReturnsConnection() throws Exception + { + TestHttpExchange exchange = new TestHttpExchange(); + Address address = newAddress(); + exchange.setAddress(address); + long delay = 5000; + exchange.setRequestURI("/?action=wait" + delay); + + HttpClient httpClient = getHttpClient(); + HttpDestination destination = httpClient.getDestination(address, false); + int connections = destination.getConnections(); + httpClient.send(exchange); + Thread.sleep(delay / 2); + Assert.assertEquals(connections + 1, destination.getConnections()); + + exchange.cancel(); + Assert.assertEquals(connections, destination.getConnections()); + } + /* ------------------------------------------------------------ */ protected abstract HttpClient getHttpClient();