Several minor fixes:
Limit size of indirect buffer for direct serving of content. default servlet redirects directories without trailing / better git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2557 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
d261713cf4
commit
6c01234e7c
|
@ -27,6 +27,12 @@ public class OneServletContext
|
|||
context.setContextPath("/");
|
||||
server.setHandler(context);
|
||||
|
||||
// Server content from tmp
|
||||
ServletHolder holder = context.addServlet(org.eclipse.jetty.servlet.DefaultServlet.class,"/tmp/*");
|
||||
holder.setInitParameter("resourceBase","/tmp");
|
||||
holder.setInitParameter("pathInfoOnly","true");
|
||||
|
||||
// Serve some hello world servlets
|
||||
context.addServlet(new ServletHolder(new HelloServlet()),"/*");
|
||||
context.addServlet(new ServletHolder(new HelloServlet("Buongiorno Mondo")),"/it/*");
|
||||
context.addServlet(new ServletHolder(new HelloServlet("Bonjour le Monde")),"/fr/*");
|
||||
|
|
|
@ -43,11 +43,20 @@ public interface HttpContent
|
|||
{
|
||||
final Resource _resource;
|
||||
final Buffer _mimeType;
|
||||
final int _maxBuffer;
|
||||
|
||||
public ResourceAsHttpContent(final Resource resource, final Buffer mimeType)
|
||||
{
|
||||
_resource=resource;
|
||||
_mimeType=mimeType;
|
||||
_maxBuffer=-1;
|
||||
}
|
||||
|
||||
public ResourceAsHttpContent(final Resource resource, final Buffer mimeType, int maxBuffer)
|
||||
{
|
||||
_resource=resource;
|
||||
_mimeType=mimeType;
|
||||
_maxBuffer=maxBuffer;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -73,6 +82,8 @@ public interface HttpContent
|
|||
{
|
||||
try
|
||||
{
|
||||
if (_maxBuffer<_resource.length())
|
||||
return null;
|
||||
ByteArrayBuffer buffer = new ByteArrayBuffer((int)_resource.length());
|
||||
buffer.readFrom(_resource.getInputStream(),(int)_resource.length());
|
||||
return buffer;
|
||||
|
|
|
@ -241,7 +241,7 @@ public class ResourceCache
|
|||
return content;
|
||||
}
|
||||
|
||||
return new HttpContent.ResourceAsHttpContent(resource,_mimeTypes.getMimeByExtension(resource.toString()));
|
||||
return new HttpContent.ResourceAsHttpContent(resource,_mimeTypes.getMimeByExtension(resource.toString()),getMaxCachedFileSize());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -122,6 +122,38 @@ public class ContextHandlerTest
|
|||
ContextHandlerCollection contexts = new ContextHandlerCollection();
|
||||
server.setHandler(contexts);
|
||||
|
||||
ContextHandler rootA = new ContextHandler(contexts,"/");
|
||||
ContextHandler fooA = new ContextHandler(contexts,"/foo");
|
||||
ContextHandler foobarA = new ContextHandler(contexts,"/foo/bar");
|
||||
|
||||
server.start();
|
||||
|
||||
// System.err.println(server.dump());
|
||||
|
||||
Assert.assertEquals(rootA._scontext,rootA._scontext.getContext("/"));
|
||||
Assert.assertEquals(fooA._scontext,rootA._scontext.getContext("/foo"));
|
||||
Assert.assertEquals(foobarA._scontext,rootA._scontext.getContext("/foo/bar"));
|
||||
Assert.assertEquals(foobarA._scontext,rootA._scontext.getContext("/foo/bar/bob.jsp"));
|
||||
Assert.assertEquals(rootA._scontext,rootA._scontext.getContext("/other"));
|
||||
Assert.assertEquals(fooA._scontext,rootA._scontext.getContext("/foo/other"));
|
||||
|
||||
Assert.assertEquals(rootA._scontext,foobarA._scontext.getContext("/"));
|
||||
Assert.assertEquals(fooA._scontext,foobarA._scontext.getContext("/foo"));
|
||||
Assert.assertEquals(foobarA._scontext,foobarA._scontext.getContext("/foo/bar"));
|
||||
Assert.assertEquals(foobarA._scontext,foobarA._scontext.getContext("/foo/bar/bob.jsp"));
|
||||
Assert.assertEquals(rootA._scontext,foobarA._scontext.getContext("/other"));
|
||||
Assert.assertEquals(fooA._scontext,foobarA._scontext.getContext("/foo/other"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextVirtualGetContext() throws Exception
|
||||
{
|
||||
Server server = new Server();
|
||||
LocalConnector connector = new LocalConnector();
|
||||
server.setConnectors(new Connector[] { connector });
|
||||
ContextHandlerCollection contexts = new ContextHandlerCollection();
|
||||
server.setHandler(contexts);
|
||||
|
||||
ContextHandler rootA = new ContextHandler(contexts,"/");
|
||||
rootA.setVirtualHosts(new String[] {"a.com"});
|
||||
|
||||
|
|
|
@ -389,7 +389,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||
}
|
||||
|
||||
String pathInContext=URIUtil.addPaths(servletPath,pathInfo);
|
||||
boolean endsWithSlash=pathInContext.endsWith(URIUtil.SLASH);
|
||||
boolean endsWithSlash=request.getRequestURI().endsWith(URIUtil.SLASH);
|
||||
|
||||
// Can we gzip this request?
|
||||
String pathInContextGz=null;
|
||||
|
@ -465,7 +465,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||
{
|
||||
// ensure we have content
|
||||
if (content==null)
|
||||
content=new HttpContent.ResourceAsHttpContent(resource,_mimeTypes.getMimeByExtension(resource.toString()));
|
||||
content=new HttpContent.ResourceAsHttpContent(resource,_mimeTypes.getMimeByExtension(resource.toString()),response.getBufferSize());
|
||||
|
||||
if (included.booleanValue() || passConditionalHeaders(request,response, resource,content))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue