Fixes #340838 (Update ConnectHandler to perform half closes properly).

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2909 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Simone Bordet 2011-03-24 10:21:17 +00:00
parent 9476b66fe5
commit 31d8a6feca
5 changed files with 97 additions and 11 deletions

View File

@ -1,5 +1,5 @@
jetty-7.3.2-SNAPSHOT jetty-7.3.2-SNAPSHOT
+ 324110 Added test harnesses for merging of QueryStrings. + 324110 Added test harnesses for merging of QueryStrings.
+ 337685 Update websocket API in preparation for draft -07 + 337685 Update websocket API in preparation for draft -07
+ 338627 HashSessionManager.getIdleSavePeriod returns milliseconds instead of seconds + 338627 HashSessionManager.getIdleSavePeriod returns milliseconds instead of seconds
+ 338819 Externally control Deployment Manager application lifecycle + 338819 Externally control Deployment Manager application lifecycle
@ -9,6 +9,7 @@ jetty-7.3.2-SNAPSHOT
+ 340265 Improve handling of io shutdown in SSL + 340265 Improve handling of io shutdown in SSL
+ Ensure generated fragment names are unique + Ensure generated fragment names are unique
+ JETTY-1245 Pooled Buffers implementation + JETTY-1245 Pooled Buffers implementation
+ 340838 Update ConnectHandler to perform half closes properly
jetty-7.3.1.v20110307 7 March 2011 jetty-7.3.1.v20110307 7 March 2011
+ 316382 Support a more strict SSL option with certificates + 316382 Support a more strict SSL option with certificates

View File

@ -509,7 +509,12 @@ public class ConnectHandler extends HandlerWrapper
if (read == -1) if (read == -1)
{ {
_logger.debug("{}: server closed connection {}", this, _endp); _logger.debug("{}: server closed connection {}", this, _endp);
close();
if (_endp.isOutputShutdown() || !_endp.isOpen())
_toClient.getEndPoint().close();
else
_toClient.getEndPoint().shutdownOutput();
break; break;
} }
@ -654,7 +659,12 @@ public class ConnectHandler extends HandlerWrapper
if (read == -1) if (read == -1)
{ {
_logger.debug("{}: client closed connection {}", this, _endp); _logger.debug("{}: client closed connection {}", this, _endp);
close();
if (_endp.isOutputShutdown() || !_endp.isOpen())
_toServer.getEndPoint().close();
else
_toServer.getEndPoint().shutdownOutput();
break; break;
} }

View File

@ -21,7 +21,7 @@ import static org.junit.Assert.assertTrue;
/** /**
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public abstract class AbstractProxyHandlerTest public abstract class AbstractConnectHandlerTest
{ {
protected static Server server; protected static Server server;
protected static Connector serverConnector; protected static Connector serverConnector;

View File

@ -1,8 +1,5 @@
package org.eclipse.jetty.server.handler; package org.eclipse.jetty.server.handler;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -13,7 +10,6 @@ import java.net.Socket;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
@ -31,10 +27,13 @@ import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
/** /**
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public class ConnectHandlerConnectSSLTest extends AbstractProxyHandlerTest public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
{ {
@BeforeClass @BeforeClass
public static void init() throws Exception public static void init() throws Exception

View File

@ -26,7 +26,7 @@ import static org.junit.Assert.assertEquals;
/** /**
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public class ConnectHandlerConnectTest extends AbstractProxyHandlerTest public class ConnectHandlerTest extends AbstractConnectHandlerTest
{ {
@BeforeClass @BeforeClass
public static void init() throws Exception public static void init() throws Exception
@ -480,6 +480,82 @@ public class ConnectHandlerConnectTest extends AbstractProxyHandlerTest
} }
} }
@Test
public void testCONNECTAndGETPipelinedAndOutputShutdown() throws Exception
{
String hostPort = "localhost:" + serverConnector.getLocalPort();
String request = "" +
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n" +
"GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
Socket socket = newSocket();
try
{
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.flush();
socket.shutdownOutput();
// Expect 200 OK from the CONNECT request
Response response = readResponse(input);
assertEquals("200", response.getCode());
// The pipelined request must have gone up to the server as is
response = readResponse(input);
assertEquals("200", response.getCode());
assertEquals("GET /echo", response.getBody());
}
finally
{
socket.close();
}
}
@Test
public void testCONNECTAndGETAndOutputShutdown() throws Exception
{
String hostPort = "localhost:" + serverConnector.getLocalPort();
String request = "" +
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
Socket socket = newSocket();
try
{
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.flush();
// Expect 200 OK from the CONNECT request
Response response = readResponse(input);
assertEquals("200", response.getCode());
request = "" +
"GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
output.write(request.getBytes("UTF-8"));
output.flush();
socket.shutdownOutput();
// The pipelined request must have gone up to the server as is
response = readResponse(input);
assertEquals("200", response.getCode());
assertEquals("GET /echo", response.getBody());
}
finally
{
socket.close();
}
}
private static class ServerHandler extends AbstractHandler private static class ServerHandler extends AbstractHandler
{ {
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException
@ -500,7 +576,7 @@ public class ConnectHandlerConnectTest extends AbstractProxyHandlerTest
while ((read = input.read()) >= 0) while ((read = input.read()) >= 0)
baos.write(read); baos.write(read);
baos.close(); baos.close();
ServletOutputStream output = httpResponse.getOutputStream(); ServletOutputStream output = httpResponse.getOutputStream();
output.println(builder.toString()); output.println(builder.toString());
output.write(baos.toByteArray()); output.write(baos.toByteArray());