Rounding out the Content-Length test scenarios
This commit is contained in:
parent
1529892105
commit
72f28e0b35
|
@ -8,10 +8,12 @@ import javax.servlet.Servlet;
|
|||
import org.eclipse.jetty.http.gzip.GzipResponseWrapper;
|
||||
import org.eclipse.jetty.servlet.FilterHolder;
|
||||
import org.eclipse.jetty.servlets.gzip.GzipTester;
|
||||
import org.eclipse.jetty.servlets.gzip.TestServletLengthStreamTypeWrite;
|
||||
import org.eclipse.jetty.servlets.gzip.TestServletLengthTypeStreamWrite;
|
||||
import org.eclipse.jetty.servlets.gzip.TestServletStreamLengthTypeWrite;
|
||||
import org.eclipse.jetty.servlets.gzip.TestServletStreamTypeLengthWrite;
|
||||
import org.eclipse.jetty.servlets.gzip.TestServletTypeLengthStreamWrite;
|
||||
import org.eclipse.jetty.servlets.gzip.TestServletTypeStreamLengthWrite;
|
||||
import org.eclipse.jetty.toolchain.test.TestingDir;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
@ -43,10 +45,12 @@ public class GzipFilterContentLengthTest
|
|||
{
|
||||
return Arrays.asList(new Object[][]
|
||||
{
|
||||
{ TestServletLengthStreamTypeWrite.class },
|
||||
{ TestServletLengthTypeStreamWrite.class },
|
||||
{ TestServletStreamLengthTypeWrite.class },
|
||||
{ TestServletStreamTypeLengthWrite.class },
|
||||
{ TestServletTypeLengthStreamWrite.class } });
|
||||
{ TestServletTypeLengthStreamWrite.class },
|
||||
{ TestServletTypeStreamLengthWrite.class } });
|
||||
}
|
||||
|
||||
private static final int LARGE = GzipResponseWrapper.DEFAULT_BUFFER_SIZE * 8;
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package org.eclipse.jetty.servlets.gzip;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.servlets.GzipFilter;
|
||||
|
||||
/**
|
||||
* A sample servlet to serve static content, using a order of construction that has caused problems for
|
||||
* {@link GzipFilter} in the past.
|
||||
*
|
||||
* Using a real-world pattern of:
|
||||
*
|
||||
* <pre>
|
||||
* 1) set content length
|
||||
* 2) get stream
|
||||
* 3) set content type
|
||||
* 4) write
|
||||
* </pre>
|
||||
*
|
||||
* @see <a href="Eclipse Bug 354014">http://bugs.eclipse.org/354014</a>
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class TestServletLengthStreamTypeWrite extends TestDirContentServlet
|
||||
{
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
String fileName = request.getServletPath();
|
||||
byte[] dataBytes = loadContentFileBytes(fileName);
|
||||
|
||||
response.setContentLength(dataBytes.length);
|
||||
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
|
||||
if (fileName.endsWith("txt"))
|
||||
response.setContentType("text/plain");
|
||||
else if (fileName.endsWith("mp3"))
|
||||
response.setContentType("audio/mpeg");
|
||||
|
||||
out.write(dataBytes);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package org.eclipse.jetty.servlets.gzip;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.servlets.GzipFilter;
|
||||
|
||||
/**
|
||||
* A sample servlet to serve static content, using a order of construction that has caused problems for
|
||||
* {@link GzipFilter} in the past.
|
||||
*
|
||||
* Using a real-world pattern of:
|
||||
*
|
||||
* <pre>
|
||||
* 1) set content type
|
||||
* 2) get stream
|
||||
* 3) set content length
|
||||
* 4) write
|
||||
* </pre>
|
||||
*
|
||||
* @see <a href="Eclipse Bug 354014">http://bugs.eclipse.org/354014</a>
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class TestServletTypeStreamLengthWrite extends TestDirContentServlet
|
||||
{
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
String fileName = request.getServletPath();
|
||||
byte[] dataBytes = loadContentFileBytes(fileName);
|
||||
|
||||
if (fileName.endsWith("txt"))
|
||||
response.setContentType("text/plain");
|
||||
else if (fileName.endsWith("mp3"))
|
||||
response.setContentType("audio/mpeg");
|
||||
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
|
||||
response.setContentLength(dataBytes.length);
|
||||
|
||||
out.write(dataBytes);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue