--- TestResponseHeaders.java.orig Wed Aug 3 16:33:47 2005 +++ TestResponseHeaders.java Wed Aug 3 17:12:56 2005 @@ -201,7 +201,7 @@ assertFalse(connectionManager.getConection().isOpen()); } - + public void testInvalidContentLength1() throws Exception { this.server.setHttpService(new HttpService() { public boolean process(SimpleRequest request, @@ -276,6 +276,45 @@ assertFalse(connectionManager.getConection().isOpen()); } + public void testNoContent() throws Exception { + // test with connection header + this.server.setRequestHandler(new HttpRequestHandler() { + public boolean processRequest(SimpleHttpServerConnection conn, + SimpleRequest request) throws IOException { + ResponseWriter out = conn.getWriter(); + out.println("HTTP/1.1 204 NO CONTENT"); + out.println(); + out.flush(); + return true; + } + }); + + GetMethod method = new GetMethod("/"); + client.executeMethod(method); + method.getResponseBodyAsString(); + + assertTrue(connectionManager.getConection().isOpen()); + + // test without connection header + this.server.setRequestHandler(new HttpRequestHandler() { + public boolean processRequest(SimpleHttpServerConnection conn, + SimpleRequest request) throws IOException { + ResponseWriter out = conn.getWriter(); + out.println("HTTP/1.1 204 NO CONTENT"); + out.println(); + out.flush(); + return true; + } + }); + + // test with connection header + method = new GetMethod("/"); + client.executeMethod(method); + method.getResponseBodyAsString(); + + assertTrue(connectionManager.getConection().isOpen()); + } + public void testNullHeaders() throws Exception { this.server.setHttpService(new HttpService() { public boolean process(SimpleRequest request, --- HttpMethodBase.java.orig Wed Aug 3 16:34:41 2005 +++ HttpMethodBase.java Wed Aug 3 17:15:28 2005 @@ -1714,7 +1714,7 @@ } } else { long expectedLength = getResponseContentLength(); - if (expectedLength == -1) { + if ((expectedLength == -1) && canResponseHaveBody(statusLine.getStatusCode())) { Header connectionHeader = responseHeaders.getFirstHeader("Connection"); String connectionDirective = null; if (connectionHeader != null) {