[Httpunit-commit] CVS: httpunit/test/com/meterware/httpunit WebClientTest.java,1.2,1.3
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-03-11 12:34:35
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv5472/test/com/meterware/httpunit
Modified Files:
WebClientTest.java
Log Message:
Send accept-encoding header unless disabled
Index: WebClientTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebClientTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WebClientTest.java 6 Mar 2002 04:59:52 -0000 1.2
+++ WebClientTest.java 11 Mar 2002 12:34:32 -0000 1.3
@@ -53,6 +53,19 @@
}
+ public void testGZIPDisabled() throws Exception {
+ String expectedResponse = "Here is my answer";
+ defineResource( "Compressed.html", new CompressedPseudoServlet( expectedResponse ) );
+ HttpUnitOptions.setAcceptGzip( false );
+
+ WebConversation wc = new WebConversation();
+ WebResponse wr = wc.getResponse( getHostPath() + "/Compressed.html" );
+ assertNull( "Should not have received a Content-Encoding header", wr.getHeaderField( "Content-encoding" ) );
+ assertEquals( "Content-Type", "text/plain", wr.getContentType() );
+ assertEquals( "Content", expectedResponse, wr.getText().trim() );
+ }
+
+
public void testGZIPHandling() throws Exception {
String expectedResponse = "Here is my answer";
defineResource( "Compressed.html", new CompressedPseudoServlet( expectedResponse ) );
@@ -76,9 +89,20 @@
public WebResource getGetResponse() throws IOException {
- WebResource result = new WebResource( getCompressedContents(), "text/plain" );
- result.addHeader( "Content-Encoding: gzip" );
- return result;
+ if (!userAcceptsGZIP()) {
+ return new WebResource( _responseText.getBytes(), "text/plain" );
+ } else {
+ WebResource result = new WebResource( getCompressedContents(), "text/plain" );
+ result.addHeader( "Content-Encoding: gzip" );
+ return result;
+ }
+ }
+
+
+ private boolean userAcceptsGZIP() {
+ String header = getHeader( "Accept-Encoding" );
+ if (header == null) return false;
+ return header.toLowerCase().indexOf( "gzip" ) >= 0;
}
|