Merge remote-tracking branch 'origin/master' into jetty-8
This commit is contained in:
commit
d5f4b157d9
|
@ -39,6 +39,7 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.toolchain.test.OS;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
|
@ -568,6 +569,21 @@ public class SslBytesServerTest extends SslBytesTest
|
|||
@Test
|
||||
public void testRequestWithCloseAlert() throws Exception
|
||||
{
|
||||
if ( !OS.IS_LINUX )
|
||||
{
|
||||
// currently we are ignoring this test on anything other then linux
|
||||
|
||||
//http://tools.ietf.org/html/rfc2246#section-7.2.1
|
||||
|
||||
// TODO (react to this portion which seems to allow win/mac behavior)
|
||||
//It is required that the other party respond with a close_notify alert of its own
|
||||
//and close down the connection immediately, discarding any pending writes. It is not
|
||||
//required for the initiator of the close to wait for the responding
|
||||
//close_notify alert before closing the read side of the connection.
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
final SSLSocket client = newClient();
|
||||
|
||||
SimpleProxy.AutomaticFlow automaticProxyFlow = proxy.startAutomaticFlow();
|
||||
|
@ -743,6 +759,20 @@ public class SslBytesServerTest extends SslBytesTest
|
|||
@Test
|
||||
public void testRequestWithCloseAlertWithSplitBoundary() throws Exception
|
||||
{
|
||||
if ( !OS.IS_LINUX )
|
||||
{
|
||||
// currently we are ignoring this test on anything other then linux
|
||||
|
||||
//http://tools.ietf.org/html/rfc2246#section-7.2.1
|
||||
|
||||
// TODO (react to this portion which seems to allow win/mac behavior)
|
||||
//It is required that the other party respond with a close_notify alert of its own
|
||||
//and close down the connection immediately, discarding any pending writes. It is not
|
||||
//required for the initiator of the close to wait for the responding
|
||||
//close_notify alert before closing the read side of the connection.
|
||||
return;
|
||||
}
|
||||
|
||||
final SSLSocket client = newClient();
|
||||
|
||||
SimpleProxy.AutomaticFlow automaticProxyFlow = proxy.startAutomaticFlow();
|
||||
|
|
|
@ -15,6 +15,8 @@ package org.eclipse.jetty.http.spi;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -25,6 +27,7 @@ import org.eclipse.jetty.server.handler.ContextHandler;
|
|||
|
||||
import com.sun.net.httpserver.Authenticator;
|
||||
import com.sun.net.httpserver.Authenticator.Result;
|
||||
import com.sun.net.httpserver.BasicAuthenticator;
|
||||
import com.sun.net.httpserver.HttpContext;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
|
@ -108,12 +111,23 @@ public class HttpSpiContextHandler extends ContextHandler
|
|||
if (result instanceof Authenticator.Failure)
|
||||
{
|
||||
int rc = ((Authenticator.Failure)result).getResponseCode();
|
||||
for (Map.Entry<String,List<String>> header : httpExchange.getResponseHeaders().entrySet())
|
||||
{
|
||||
for (String value : header.getValue())
|
||||
resp.addHeader(header.getKey(),value);
|
||||
}
|
||||
resp.sendError(rc);
|
||||
}
|
||||
else if (result instanceof Authenticator.Retry)
|
||||
{
|
||||
int rc = ((Authenticator.Retry)result).getResponseCode();
|
||||
resp.sendError(rc);
|
||||
for (Map.Entry<String,List<String>> header : httpExchange.getResponseHeaders().entrySet())
|
||||
{
|
||||
for (String value : header.getValue())
|
||||
resp.addHeader(header.getKey(),value);
|
||||
}
|
||||
resp.setStatus(rc);
|
||||
resp.flushBuffer();
|
||||
}
|
||||
else if (result instanceof Authenticator.Success)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
package org.eclipse.jetty.http.spi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sun.net.httpserver.BasicAuthenticator;
|
||||
import com.sun.net.httpserver.Headers;
|
||||
import com.sun.net.httpserver.HttpContext;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
|
||||
|
||||
public class TestSPIServer
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
String host="localhost";
|
||||
int port = 8080;
|
||||
|
||||
HttpServer server = new JettyHttpServerProvider().createHttpServer(new
|
||||
InetSocketAddress(host, port), 10);
|
||||
server.start();
|
||||
|
||||
final HttpContext httpContext = server.createContext("/",
|
||||
new HttpHandler()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException
|
||||
{
|
||||
Headers responseHeaders = exchange.getResponseHeaders();
|
||||
responseHeaders.set("Content-Type","text/plain");
|
||||
exchange.sendResponseHeaders(200,0);
|
||||
|
||||
OutputStream responseBody = exchange.getResponseBody();
|
||||
Headers requestHeaders = exchange.getRequestHeaders();
|
||||
Set<String> keySet = requestHeaders.keySet();
|
||||
Iterator<String> iter = keySet.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
String key = iter.next();
|
||||
List values = requestHeaders.get(key);
|
||||
String s = key + " = " + values.toString() + "\n";
|
||||
responseBody.write(s.getBytes());
|
||||
}
|
||||
responseBody.close();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
httpContext.setAuthenticator(new BasicAuthenticator("Test")
|
||||
{
|
||||
@Override
|
||||
public boolean checkCredentials(String username, String password)
|
||||
{
|
||||
if ("username".equals(username) && password.equals("password"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Thread.sleep(10000000);
|
||||
|
||||
}
|
||||
}
|
|
@ -18,12 +18,14 @@ import java.io.InputStream;
|
|||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.util.concurrent.Exchanger;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.net.ssl.SSLException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.junit.Assert;
|
||||
|
@ -108,7 +110,23 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
|
|||
@Test
|
||||
public void testMaxIdleWithRequest10NoClientClose() throws Exception
|
||||
{
|
||||
configureServer(new HelloWorldHandler());
|
||||
final Exchanger<EndPoint> endpoint = new Exchanger<EndPoint>();
|
||||
configureServer(new HelloWorldHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException,
|
||||
ServletException
|
||||
{
|
||||
try
|
||||
{
|
||||
endpoint.exchange(baseRequest.getConnection().getEndPoint());
|
||||
}
|
||||
catch(Exception e)
|
||||
{}
|
||||
super.handle(target,baseRequest,request,response);
|
||||
}
|
||||
|
||||
});
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
client.setSoTimeout(10000);
|
||||
|
||||
|
@ -124,16 +142,29 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
|
|||
"\r\n").getBytes("utf-8"));
|
||||
os.flush();
|
||||
|
||||
// Get the server side endpoint
|
||||
EndPoint endp = endpoint.exchange(null,10,TimeUnit.SECONDS);
|
||||
|
||||
// read the response
|
||||
String result=IO.toString(is);
|
||||
Assert.assertThat("OK",result,containsString("200 OK"));
|
||||
|
||||
// check the server side is open and oshut and that client reads EOF
|
||||
Assert.assertTrue(endp.isOpen());
|
||||
Assert.assertTrue(endp.isOutputShutdown());
|
||||
Assert.assertFalse(endp.isInputShutdown());
|
||||
assertEquals(-1, is.read());
|
||||
|
||||
TimeUnit.MILLISECONDS.sleep(MAX_IDLE_TIME);
|
||||
// wait for idle timeout
|
||||
TimeUnit.MILLISECONDS.sleep(MAX_IDLE_TIME+MAX_IDLE_TIME/2);
|
||||
|
||||
// check the server side is closed
|
||||
Assert.assertFalse(endp.isOpen());
|
||||
|
||||
// further writes will get broken pipe or similar
|
||||
try
|
||||
{
|
||||
for (int i=0;i<100;i++)
|
||||
for (int i=0;i<1000;i++)
|
||||
{
|
||||
os.write((
|
||||
"GET / HTTP/1.0\r\n"+
|
||||
|
@ -153,7 +184,23 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
|
|||
@Test
|
||||
public void testMaxIdleWithRequest11NoClientClose() throws Exception
|
||||
{
|
||||
configureServer(new EchoHandler());
|
||||
final Exchanger<EndPoint> endpoint = new Exchanger<EndPoint>();
|
||||
configureServer(new EchoHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException,
|
||||
ServletException
|
||||
{
|
||||
try
|
||||
{
|
||||
endpoint.exchange(baseRequest.getConnection().getEndPoint());
|
||||
}
|
||||
catch(Exception e)
|
||||
{}
|
||||
super.handle(target,baseRequest,request,response);
|
||||
}
|
||||
|
||||
});
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
client.setSoTimeout(10000);
|
||||
|
||||
|
@ -173,17 +220,28 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
|
|||
"\r\n").getBytes("utf-8"));
|
||||
os.write(contentB);
|
||||
os.flush();
|
||||
|
||||
|
||||
// Get the server side endpoint
|
||||
EndPoint endp = endpoint.exchange(null,10,TimeUnit.SECONDS);
|
||||
|
||||
// read the response
|
||||
IO.toString(is);
|
||||
|
||||
// check the server side is open and oshut and that client reads EOF
|
||||
Assert.assertTrue(endp.isOpen());
|
||||
Assert.assertTrue(endp.isOutputShutdown());
|
||||
Assert.assertFalse(endp.isInputShutdown());
|
||||
assertEquals(-1, is.read());
|
||||
|
||||
TimeUnit.MILLISECONDS.sleep(MAX_IDLE_TIME);
|
||||
TimeUnit.MILLISECONDS.sleep(MAX_IDLE_TIME+MAX_IDLE_TIME/2);
|
||||
|
||||
// check the server side is closed
|
||||
Assert.assertFalse(endp.isOpen());
|
||||
|
||||
// further writes will get broken pipe or similar
|
||||
try
|
||||
{
|
||||
for (int i=0;i<100;i++)
|
||||
for (int i=0;i<1000;i++)
|
||||
{
|
||||
os.write((
|
||||
"GET / HTTP/1.0\r\n"+
|
||||
|
|
Loading…
Reference in New Issue