Instituting Content-Length OR Transfer-Encoding check in GzipFilter tests

+ Tests currently fail, will let greg look deeply into jetty's eyes to
  determine why it defiantly doesn't want to cooperate with greg.
This commit is contained in:
Joakim Erdfelt 2013-06-30 16:37:08 -07:00
parent f262dce23b
commit aa1aae182a
2 changed files with 13 additions and 13 deletions

View File

@ -18,13 +18,8 @@
package org.eclipse.jetty.servlets.gzip; package org.eclipse.jetty.servlets.gzip;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.*;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -56,7 +51,6 @@ import org.eclipse.jetty.testing.ServletTester;
import org.eclipse.jetty.toolchain.test.IO; import org.eclipse.jetty.toolchain.test.IO;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.TestingDir; import org.eclipse.jetty.toolchain.test.TestingDir;
import org.eclipse.jetty.util.DateCache;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Assert; import org.junit.Assert;
@ -116,10 +110,15 @@ public class GzipTester
// Assert the response headers // Assert the response headers
Assert.assertThat("Response.method",response.getMethod(),nullValue()); Assert.assertThat("Response.method",response.getMethod(),nullValue());
// Assert.assertThat("Response.status",response.getStatus(),is(HttpServletResponse.SC_OK));
if ( response.getHeader("X-Testing-Skip-Content-Length") == null ) // Response headers should have either a Transfer-Encoding indicating chunked OR a Content-Length
{ String contentLength = response.getHeader("Content-Length");
Assert.assertThat("Response.header[Content-Length]",response.getHeader("Content-Length"),notNullValue()); String transferEncoding = response.getHeader("Transfer-Encoding");
boolean chunked = (transferEncoding != null) && (transferEncoding.indexOf("chunk") >= 0);
if(!chunked) {
Assert.assertThat("Response.header[Content-Length]",contentLength,notNullValue());
} else {
Assert.assertThat("Response.header[Transfer-Encoding]",transferEncoding,notNullValue());
} }
int qindex = compressionType.indexOf(";"); int qindex = compressionType.indexOf(";");

View File

@ -53,8 +53,8 @@ public class TestServletStreamLengthTypeWriteWithFlush extends TestDirContentSer
ServletOutputStream out = response.getOutputStream(); ServletOutputStream out = response.getOutputStream();
// set content-length of uncompressed content (GzipFilter should handle this)
response.setContentLength(dataBytes.length); response.setContentLength(dataBytes.length);
response.setHeader("X-Testing-Skip-Content-Length","true");
if (fileName.endsWith("txt")) if (fileName.endsWith("txt"))
response.setContentType("text/plain"); response.setContentType("text/plain");
@ -65,6 +65,7 @@ public class TestServletStreamLengthTypeWriteWithFlush extends TestDirContentSer
for ( int i = 0 ; i < dataBytes.length ; i++) for ( int i = 0 ; i < dataBytes.length ; i++)
{ {
out.write(dataBytes[i]); out.write(dataBytes[i]);
// flush using response object (not the stream itself)
response.flushBuffer(); response.flushBuffer();
} }
} }