Merge remote-tracking branch 'origin/jetty-7' into jetty-8
This commit is contained in:
commit
3849c893e1
|
@ -580,6 +580,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void addHeader(String name, String value)
|
||||
{
|
||||
|
||||
if (_connection.isIncluding())
|
||||
{
|
||||
if (name.startsWith(SET_INCLUDE_HEADER_PREFIX))
|
||||
|
@ -588,6 +589,12 @@ public class Response implements HttpServletResponse
|
|||
return;
|
||||
}
|
||||
|
||||
if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name))
|
||||
{
|
||||
setContentType(value);
|
||||
return;
|
||||
}
|
||||
|
||||
_connection.getResponseFields().add(name, value);
|
||||
if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name))
|
||||
_connection._generator.setContentLength(Long.parseLong(value));
|
||||
|
|
|
@ -172,6 +172,10 @@ public class ResponseTest
|
|||
response.setContentType("foo/bar");
|
||||
assertEquals("foo/bar", response.getContentType());
|
||||
|
||||
response.recycle();
|
||||
response.addHeader("Content-Type","text/something");
|
||||
assertEquals("text/something",response.getContentType());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -756,6 +756,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;
|
||||
}
|
||||
|
@ -769,6 +771,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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -47,6 +47,8 @@ import java.util.zip.InflaterInputStream;
|
|||
import javax.servlet.Servlet;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
import org.eclipse.jetty.http.HttpHeaders;
|
||||
import org.eclipse.jetty.io.ByteArrayBuffer;
|
||||
import org.eclipse.jetty.servlet.FilterHolder;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
|
@ -56,6 +58,7 @@ import org.eclipse.jetty.testing.ServletTester;
|
|||
import org.eclipse.jetty.toolchain.test.IO;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.toolchain.test.TestingDir;
|
||||
import org.eclipse.jetty.util.DateCache;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Assert;
|
||||
|
||||
|
@ -80,10 +83,20 @@ public class GzipTester
|
|||
{
|
||||
return assertIsResponseGzipCompressed(method,filename,filename);
|
||||
}
|
||||
|
||||
public HttpTester assertIsResponseGzipCompressed(String method,String filename,long ifmodifiedsince) throws Exception
|
||||
{
|
||||
return assertIsResponseGzipCompressed(method,filename,filename,ifmodifiedsince);
|
||||
}
|
||||
|
||||
public HttpTester assertIsResponseGzipCompressed(String method,String requestedFilename, String serverFilename) throws Exception
|
||||
{
|
||||
System.err.printf("[GzipTester] requesting /context/%s%n",requestedFilename);
|
||||
return assertIsResponseGzipCompressed(method,requestedFilename,serverFilename,-1);
|
||||
}
|
||||
|
||||
public HttpTester assertIsResponseGzipCompressed(String method,String requestedFilename, String serverFilename, long ifmodifiedsince) throws Exception
|
||||
{
|
||||
//System.err.printf("[GzipTester] requesting /context/%s%n",requestedFilename);
|
||||
HttpTester request = new HttpTester();
|
||||
HttpTester response = new HttpTester();
|
||||
|
||||
|
@ -91,6 +104,8 @@ public class GzipTester
|
|||
request.setVersion("HTTP/1.0");
|
||||
request.setHeader("Host","tester");
|
||||
request.setHeader("Accept-Encoding",compressionType);
|
||||
if (ifmodifiedsince>0)
|
||||
request.setHeader(HttpHeaders.IF_MODIFIED_SINCE,HttpFields.formatDate(ifmodifiedsince));
|
||||
if (this.userAgent != null)
|
||||
request.setHeader("User-Agent", this.userAgent);
|
||||
request.setURI("/context/" + requestedFilename);
|
||||
|
@ -100,7 +115,7 @@ public class GzipTester
|
|||
// Collect the response(s)
|
||||
ByteArrayBuffer respBuff = servletTester.getResponses(reqsBuff);
|
||||
response.parse(respBuff.asArray());
|
||||
|
||||
|
||||
// Assert the response headers
|
||||
Assert.assertThat("Response.method",response.getMethod(),nullValue());
|
||||
// Assert.assertThat("Response.status",response.getStatus(),is(HttpServletResponse.SC_OK));
|
||||
|
@ -147,6 +162,41 @@ public class GzipTester
|
|||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
public HttpTester assertIsResponseNotModified(String method,String requestedFilename, long ifmodifiedsince) throws Exception
|
||||
{
|
||||
return assertIsResponseNotModified(method,requestedFilename,requestedFilename,ifmodifiedsince);
|
||||
}
|
||||
|
||||
public HttpTester assertIsResponseNotModified(String method,String requestedFilename, String serverFilename, long ifmodifiedsince) throws Exception
|
||||
{
|
||||
//System.err.printf("[GzipTester] requesting /context/%s%n",requestedFilename);
|
||||
HttpTester request = new HttpTester();
|
||||
HttpTester response = new HttpTester();
|
||||
|
||||
request.setMethod(method);
|
||||
request.setVersion("HTTP/1.0");
|
||||
request.setHeader("Host","tester");
|
||||
request.setHeader("Accept-Encoding",compressionType);
|
||||
if (ifmodifiedsince>0)
|
||||
request.setHeader(HttpHeaders.IF_MODIFIED_SINCE,HttpFields.formatDate(ifmodifiedsince));
|
||||
if (this.userAgent != null)
|
||||
request.setHeader("User-Agent", this.userAgent);
|
||||
request.setURI("/context/" + requestedFilename);
|
||||
|
||||
// Issue the request
|
||||
ByteArrayBuffer reqsBuff = new ByteArrayBuffer(request.generate().getBytes());
|
||||
// Collect the response(s)
|
||||
ByteArrayBuffer respBuff = servletTester.getResponses(reqsBuff);
|
||||
response.parse(respBuff.asArray());
|
||||
|
||||
Assert.assertThat(response.getStatus(),Matchers.equalTo(304));
|
||||
Assert.assertThat(response.getHeader("ETag"),Matchers.startsWith("W/"));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Makes sure that the response contains an unfiltered file contents.
|
||||
|
@ -165,7 +215,7 @@ public class GzipTester
|
|||
*/
|
||||
public void assertIsResponseNotGzipFiltered(String requestedFilename, String testResourceSha1Sum, String expectedContentType) throws Exception
|
||||
{
|
||||
System.err.printf("[GzipTester] requesting /context/%s%n",requestedFilename);
|
||||
// System.err.printf("[GzipTester] requesting /context/%s%n",requestedFilename);
|
||||
HttpTester request = new HttpTester();
|
||||
HttpTester response = new HttpTester();
|
||||
|
||||
|
@ -328,7 +378,7 @@ public class GzipTester
|
|||
|
||||
private HttpTester executeRequest(String method,String uri) throws IOException, Exception
|
||||
{
|
||||
System.err.printf("[GzipTester] requesting %s%n",uri);
|
||||
//System.err.printf("[GzipTester] requesting %s%n",uri);
|
||||
HttpTester request = new HttpTester();
|
||||
HttpTester response = new HttpTester();
|
||||
|
||||
|
|
Loading…
Reference in New Issue