diff --git a/VERSION.txt b/VERSION.txt index f529e53698d..5879d444b60 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -2,6 +2,7 @@ + 328199 Ensure blocking connectors always close socket + 328205 Improved SelectManager stopping + 328306 Serialization of FormAuthentication + + 328332 Response.getContentType works with setHeader jetty-7.2.0.v20101020 20 October 2010 + 289540 added javadoc into distribution diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/AbstractGenerator.java b/jetty-http/src/main/java/org/eclipse/jetty/http/AbstractGenerator.java index db0db7902f5..023ad96835d 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/AbstractGenerator.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/AbstractGenerator.java @@ -260,7 +260,7 @@ public abstract class AbstractGenerator implements Generator ?_persistent.booleanValue() :(isRequest()?true:_version>HttpVersions.HTTP_1_0_ORDINAL); } - + /* ------------------------------------------------------------ */ public void setPersistent(boolean persistent) { diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/bio/SocketEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/bio/SocketEndPoint.java index cc33561baee..a4f8140d367 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/bio/SocketEndPoint.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/bio/SocketEndPoint.java @@ -21,7 +21,6 @@ import java.net.Socket; import org.eclipse.jetty.util.StringUtil; /** - * * * To change the template for this generated type comment go to * Window - Preferences - Java - Code Generation - Code and Comments diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java index 0f67c9f49f7..fce6b7f1943 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java @@ -658,6 +658,9 @@ public class HttpConnection implements Connection // send the body anyway, or close. So we no longer need to // do anything special here. _expect100Continue = false; + + if (!_response.isCommitted()) + _generator.setPersistent(false); } if(_endp.isOpen()) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java index 688126af93a..35d5be2415f 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java @@ -17,7 +17,6 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.Collections; import java.util.Enumeration; -import java.util.List; import java.util.Locale; import javax.servlet.ServletOutputStream; @@ -39,7 +38,6 @@ import org.eclipse.jetty.io.BufferCache.CachedBuffer; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ErrorHandler; import org.eclipse.jetty.util.ByteArrayISO8859Writer; -import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.QuotedStringTokenizer; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.URIUtil; @@ -64,15 +62,6 @@ public class Response implements HttpServletResponse */ public final static String SET_INCLUDE_HEADER_PREFIX = "org.eclipse.jetty.server.include."; - private static final PrintWriter __nullPrintWriter; - private static final ServletOutputStream __nullServletOut; - - static - { - __nullPrintWriter = new PrintWriter(IO.getNullWriter()); - __nullServletOut = new NullOutput(); - } - private final HttpConnection _connection; private int _status=SC_OK; private String _reason; @@ -472,20 +461,25 @@ public class Response implements HttpServletResponse */ public void setHeader(String name, String value) { - if (_connection.isIncluding()) + if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name)) + setContentType(value); + else { - if (name.startsWith(SET_INCLUDE_HEADER_PREFIX)) - name=name.substring(SET_INCLUDE_HEADER_PREFIX.length()); - else - return; - } - _connection.getResponseFields().put(name, value); - if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name)) - { - if (value==null) - _connection._generator.setContentLength(-1); - else - _connection._generator.setContentLength(Long.parseLong(value)); + if (_connection.isIncluding()) + { + if (name.startsWith(SET_INCLUDE_HEADER_PREFIX)) + name=name.substring(SET_INCLUDE_HEADER_PREFIX.length()); + else + return; + } + _connection.getResponseFields().put(name, value); + if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name)) + { + if (value==null) + _connection._generator.setContentLength(-1); + else + _connection._generator.setContentLength(Long.parseLong(value)); + } } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/bio/SocketConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/bio/SocketConnector.java index 36df99e7e11..7af5e1c7fc2 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/bio/SocketConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/bio/SocketConnector.java @@ -267,10 +267,24 @@ public class SocketConnector extends AbstractConnector _connections.remove(this); } - // ensure it really is closed and not just shutdown. + // wait for client to close, but if not, close ourselves. try { - _socket.close(); + if (!_socket.isClosed()) + { + long timestamp=System.currentTimeMillis(); + int max_idle=getMaxIdleTime(); + + _socket.setSoTimeout(getMaxIdleTime()); + int c=0; + do + { + c = _socket.getInputStream().read(); + } + while (c>=0 && (System.currentTimeMillis()-timestamp)=0 && (System.currentTimeMillis()-timestamp)0); + assertTrue(in.indexOf("Hello world")>0); + + } + finally + { + client.close(); + } + } + + /** * Read entire response from the client. Close the output. * diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java index af169518541..75b18d01419 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java @@ -78,6 +78,9 @@ public class ResponseTest assertEquals(null,response.getContentType()); + response.setHeader("Content-Type","text/something"); + assertEquals("text/something",response.getContentType()); + response.setContentType("foo/bar"); assertEquals("foo/bar",response.getContentType()); response.getWriter(); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSelectChannelServerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSelectChannelServerTest.java index 5f6a991af62..1754b863979 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSelectChannelServerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSelectChannelServerTest.java @@ -67,5 +67,11 @@ public class SslSelectChannelServerTest extends HttpServerTestBase { // TODO this test uses URL, so noop for now } - + + @Test + @Override + public void testBlockedClient() throws Exception + { + } + } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSocketServerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSocketServerTest.java index 6e2dbb1a04a..4b13a838e07 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSocketServerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSocketServerTest.java @@ -66,5 +66,5 @@ public class SslSocketServerTest extends HttpServerTestBase { // TODO this test uses URL, so noop for now } - + } diff --git a/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java b/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java index c70f65ce162..25bbaee7ec1 100644 --- a/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java +++ b/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java @@ -34,6 +34,7 @@ import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.HandlerWrapper; import org.eclipse.jetty.server.handler.RequestLogHandler; +import org.eclipse.jetty.server.nio.BlockingChannelConnector; import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.server.session.HashSessionManager; import org.eclipse.jetty.server.ssl.SslSelectChannelConnector; @@ -87,6 +88,13 @@ public class TestServer connector2.setMaxIdleTime(30000); connector2.setConfidentialPort(8443); server.addConnector(connector2); + + // Setup Connectors + BlockingChannelConnector connector3 = new BlockingChannelConnector(); + connector3.setPort(8083); + connector3.setMaxIdleTime(30000); + connector3.setConfidentialPort(8443); + server.addConnector(connector3); SslSelectChannelConnector ssl_connector = new SslSelectChannelConnector(); ssl_connector.setPort(8443); diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java index 026b1a4bfd7..2f61564e477 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java @@ -721,8 +721,11 @@ public abstract class RFC2616BaseTest response.assertStatusOK("8.2.3 expect 100"); } + + /** * Test Message Transmission Requirements -- Acceptable bad client behavior, Expect 100 with body content. + * @throws Exception failure * * @see RFC 2616 (section 8.2) */ @@ -749,10 +752,15 @@ public abstract class RFC2616BaseTest List responses = http.requests(req3); + System.err.println(responses); + response=responses.get(0); + System.err.println(response.getRawResponse()); + response.assertStatus("8.2.3 ignored no 100",302); response=responses.get(1); + System.err.println(response.getRawResponse()); response.assertStatus("8.2.3 ignored no 100",200); response.assertBody("87654321\n"); }