Merge remote-tracking branch 'origin/jetty-8'

Conflicts:
	jetty-server/src/main/java/org/eclipse/jetty/server/Response.java
	jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java
	jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java
This commit is contained in:
Greg Wilkins 2013-05-31 18:06:34 +10:00
commit 842309e656
4 changed files with 66 additions and 1 deletions

View File

@ -613,6 +613,12 @@ public class Response implements HttpServletResponse
return;
}
if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name))
{
setContentType(value);
return;
}
_fields.add(name, value);
if (HttpHeader.CONTENT_LENGTH.is(name))
{

View File

@ -202,6 +202,10 @@ public class ResponseTest
response.setCharacterEncoding(null);
response.setContentType("foo/bar");
assertEquals("foo/bar", response.getContentType());
response.recycle();
response.addHeader("Content-Type","text/something");
assertEquals("text/something",response.getContentType());
}
@Test

View File

@ -738,6 +738,8 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
{
r.reset(true);
r.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
if (_etags)
r.getHttpFields().add(HttpHeaders.ETAG_BUFFER,content.getETag());
r.flushBuffer();
return false;
}
@ -751,6 +753,8 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
{
r.reset(true);
r.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
if (_etags)
r.getHttpFields().add(HttpHeaders.ETAG_BUFFER,content.getETag());
r.flushBuffer();
return false;
}

View File

@ -145,7 +145,7 @@ public class GzipFilterDefaultTest
String uri=req.getRequestURI();
if (uri.endsWith(".deferred"))
{
System.err.println("type for "+uri.substring(0,uri.length()-9)+" is "+getServletContext().getMimeType(uri.substring(0,uri.length()-9)));
// System.err.println("type for "+uri.substring(0,uri.length()-9)+" is "+getServletContext().getMimeType(uri.substring(0,uri.length()-9)));
resp.setContentType(getServletContext().getMimeType(uri.substring(0,uri.length()-9)));
}
@ -272,6 +272,57 @@ public class GzipFilterDefaultTest
tester.stop();
}
}
@Test
public void testGzipedIfModified() throws Exception
{
GzipTester tester = new GzipTester(testingdir, compressionType);
// Test content that is smaller than the buffer.
int filesize = CompressedResponseWrapper.DEFAULT_BUFFER_SIZE * 4;
tester.prepareServerFile("file.txt",filesize);
FilterHolder holder = tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class);
holder.setInitParameter("mimeTypes","text/plain");
try
{
tester.start();
HttpTester http = tester.assertIsResponseGzipCompressed("GET","file.txt",System.currentTimeMillis()-4000);
Assert.assertEquals("Accept-Encoding",http.getHeader("Vary"));
}
finally
{
tester.stop();
}
}
@Test
public void testNotGzipedIfNotModified() throws Exception
{
GzipTester tester = new GzipTester(testingdir, compressionType);
// Test content that is smaller than the buffer.
int filesize = CompressedResponseWrapper.DEFAULT_BUFFER_SIZE * 4;
tester.prepareServerFile("file.txt",filesize);
FilterHolder holder = tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class);
holder.setInitParameter("mimeTypes","text/plain");
holder.setInitParameter("etags","true");
try
{
tester.start();
HttpTester http = tester.assertIsResponseNotModified("GET","file.txt",System.currentTimeMillis()+4000);
}
finally
{
tester.stop();
}
}
@Test
public void testIsNotGzipCompressedWithQ() throws Exception