Merge remote-tracking branch 'origin/jetty-9.2.x'

Conflicts:
	jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
	jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java
	jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java
This commit is contained in:
Greg Wilkins 2014-11-20 16:34:30 +11:00
commit ab2e9c357f
10 changed files with 67 additions and 10 deletions

View File

@ -180,7 +180,17 @@ public class HttpFields implements Iterable<HttpField>
}
return false;
}
public boolean contains(HttpHeader header)
{
for (int i=_size;i-->0;)
{
HttpField f=_fields[i];
if (f.getHeader()==header)
return true;
}
return false;
}
public boolean containsKey(String name)
{
@ -192,7 +202,8 @@ public class HttpFields implements Iterable<HttpField>
}
return false;
}
public String get(HttpHeader header)
{
for (int i=0;i<_size;i++)

View File

@ -79,7 +79,7 @@ public class ContainerTldBundleDiscoverer implements TldBundleDiscoverer
* we locate the corresponding bundle and register it as a bundle that
* contains tld files.
*/
private static String DEFAULT_JSTL_BUNDLE_CLASS = "org.apache.taglibs.standard.tag.el.core.WhenTag";
private static String DEFAULT_JSTL_BUNDLE_CLASS = "org.apache.taglibs.standard.tag.rt.core.WhenTag";
private Bundle jstlBundle = null;

View File

@ -185,9 +185,14 @@ public class EnvConfiguration extends AbstractConfiguration
@Override
public void destroy (WebAppContext context) throws Exception
{
ClassLoader old_loader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(context.getClassLoader());
ContextFactory.associateClassLoader(context.getClassLoader());
try
{
//unbind any NamingEntries that were configured in this webapp's name space
NamingContext scopeContext = (NamingContext)NamingEntryUtil.getContextForScope(context);
scopeContext.getParent().destroySubcontext(scopeContext.getName());
}
@ -196,6 +201,11 @@ public class EnvConfiguration extends AbstractConfiguration
LOG.ignore(e);
LOG.debug("No naming entries configured in environment for webapp "+context);
}
finally
{
ContextFactory.disassociateClassLoader();
Thread.currentThread().setContextClassLoader(old_loader);
}
}
/**

View File

@ -503,8 +503,9 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
{
_requests.incrementAndGet();
_request.setTimeStamp(System.currentTimeMillis());
if (_configuration.getSendDateHeader())
_response.getHttpFields().put(_connector.getServer().getDateField());
HttpFields fields = _response.getHttpFields();
if (_configuration.getSendDateHeader() && !fields.contains(HttpHeader.DATE))
fields.put(_connector.getServer().getDateField());
_request.setMetaData(request);
}

View File

@ -40,7 +40,7 @@ public class HttpChannelState
{
private static final Logger LOG = Log.getLogger(HttpChannelState.class);
private final static long DEFAULT_TIMEOUT=30000L;
private final static long DEFAULT_TIMEOUT=Long.getLong("org.eclipse.jetty.server.HttpChannelState.DEFAULT_TIMEOUT",30000L);
/** The dispatched state of the HttpChannel, used to control the overall livecycle
*/

View File

@ -63,9 +63,9 @@ public class ResourceCache
private final boolean _etagSupported;
private final boolean _useFileMappedBuffer;
private int _maxCachedFileSize =4*1024*1024;
private int _maxCachedFileSize =128*1024*1024;
private int _maxCachedFiles=2048;
private int _maxCacheSize =32*1024*1024;
private int _maxCacheSize =256*1024*1024;
/* ------------------------------------------------------------ */
/** Constructor.
@ -302,7 +302,7 @@ public class ResourceCache
{
try
{
if (_useFileMappedBuffer && resource.getFile()!=null)
if (_useFileMappedBuffer && resource.getFile()!=null && resource.length()<Integer.MAX_VALUE)
return BufferUtil.toMappedBuffer(resource.getFile());
return BufferUtil.toBuffer(resource,true);

View File

@ -72,7 +72,7 @@ public class ResourceHandler extends HandlerWrapper
String _cacheControl;
boolean _directory;
boolean _etags;
int _minMemoryMappedContentLength=-1;
int _minMemoryMappedContentLength=1024;
int _minAsyncContentLength=0;
/* ------------------------------------------------------------ */
@ -521,6 +521,7 @@ public class ResourceHandler extends HandlerWrapper
resource.length()>=min_async_size)
{
final AsyncContext async = request.startAsync();
async.setTimeout(0);
Callback callback = new Callback()
{
@Override
@ -541,6 +542,7 @@ public class ResourceHandler extends HandlerWrapper
// Can we use a memory mapped file?
if (_minMemoryMappedContentLength>0 &&
resource.length()>_minMemoryMappedContentLength &&
resource.length()<Integer.MAX_VALUE &&
resource instanceof PathResource)
{
ByteBuffer buffer = BufferUtil.toMappedBuffer(resource.getFile());

View File

@ -81,6 +81,9 @@ public class DumpHandler extends AbstractHandler
read.append((char)in.read());
}
if (request.getParameter("date")!=null)
response.setHeader("Date",request.getParameter("date"));
if (request.getParameter("ISE")!=null)
{
throw new IllegalStateException("Testing ISE");

View File

@ -73,6 +73,7 @@ public class HttpConnectionTest
connector = new LocalConnector(server,http,null);
connector.setIdleTimeout(5000);
connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setSendDateHeader(true);
server.addConnector(connector);
server.setHandler(new DumpHandler());
ErrorHandler eh=new ErrorHandler();
@ -146,6 +147,34 @@ public class HttpConnectionTest
checkContains(response,offset,"pathInfo=/");
}
@Test
public void testDate() throws Exception
{
String response=connector.getResponses("GET / HTTP/1.1\n"+
"Host: localhost:80\n"+
"Connection: close\n"+
"\n");
int offset=0;
offset = checkContains(response,offset,"HTTP/1.1 200");
offset = checkContains(response,offset,"Date: ");
checkContains(response,offset,"pathInfo=/");
}
@Test
public void testSetDate() throws Exception
{
String response=connector.getResponses("GET /?date=1+Jan+1970 HTTP/1.1\n"+
"Host: localhost:80\n"+
"Connection: close\n"+
"\n");
int offset=0;
offset = checkContains(response,offset,"HTTP/1.1 200");
offset = checkContains(response,offset,"Date: 1 Jan 1970");
checkContains(response,offset,"pathInfo=/");
}
@Test
public void testBadNoPath() throws Exception
{

View File

@ -953,6 +953,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
if (request.isAsyncSupported())
{
final AsyncContext context = request.startAsync();
context.setTimeout(0);
((HttpOutput)out).sendContent(content,new Callback()
{