JETTY-1533 handle URL with no path

This commit is contained in:
Greg Wilkins 2012-12-13 07:59:21 +11:00
parent b1a7779bd2
commit a478271828
2 changed files with 35 additions and 0 deletions

View File

@ -467,7 +467,10 @@ public abstract class AbstractHttpConnection extends AbstractConnection
if (info==null && !_request.getMethod().equals(HttpMethods.CONNECT))
{
if (_uri.getScheme()!=null && _uri.getHost()!=null)
{
info="/";
_request.setRequestURI("");
}
else
throw new HttpException(400);
}

View File

@ -35,7 +35,9 @@ import javax.servlet.ServletResponse;
import junit.framework.Assert;
import org.eclipse.jetty.server.LocalConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceCollection;
@ -185,6 +187,36 @@ public class WebAppContextTest
assertFalse(context.isProtectedTarget("/something-else/web-inf"));
}
@Test
public void testNullPath() throws Exception
{
Server server = new Server(0);
HandlerList handlers = new HandlerList();
ContextHandlerCollection contexts = new ContextHandlerCollection();
WebAppContext context = new WebAppContext();
context.setBaseResource(Resource.newResource("./src/test/webapp"));
context.setContextPath("/");
server.setHandler(handlers);
handlers.addHandler(contexts);
contexts.addHandler(context);
LocalConnector connector = new LocalConnector();
server.addConnector(connector);
server.start();
try
{
String response = connector.getResponses("GET http://localhost:8080 HTTP/1.1\r\nHost: localhost:8080\r\nConnection: close\r\n\r\n");
Assert.assertTrue(response.indexOf("200 OK")>=0);
}
finally
{
server.stop();
}
}
class ServletA extends GenericServlet
{
@Override