[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit HttpWebResponse.java,1.20,1.21 WebRespons
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-03-06 04:59:55
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv9204/src/com/meterware/httpunit
Modified Files:
HttpWebResponse.java WebResponse.java
Log Message:
Added support for gzip-encoded responses
Index: HttpWebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- HttpWebResponse.java 6 Mar 2002 03:45:57 -0000 1.20
+++ HttpWebResponse.java 6 Mar 2002 04:59:52 -0000 1.21
@@ -2,14 +2,14 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, Russell Gold
*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
-* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
-* The above copyright notice and this permission notice shall be included in all copies or substantial portions
+* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
@@ -31,7 +31,7 @@
import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Vector;
-
+
/**
* A response from a web server to an Http request.
@@ -118,7 +118,7 @@
private Hashtable _headers = new Hashtable();
-
+
private void readResponseHeader( URLConnection connection ) {
if (connection.getHeaderField(0) == null) throw new HttpNotFoundException( connection.getURL() );
@@ -166,7 +166,7 @@
if (connection.getContentType() != null) {
setContentTypeHeader( connection.getContentType() );
- }
+ }
}
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -r1.63 -r1.64
--- WebResponse.java 6 Mar 2002 03:45:57 -0000 1.63
+++ WebResponse.java 6 Mar 2002 04:59:52 -0000 1.64
@@ -20,13 +20,7 @@
*
*******************************************************************************************************************/
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.StreamTokenizer;
-import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
+import java.io.*;
import java.lang.reflect.Constructor;
@@ -40,6 +34,7 @@
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
+import java.util.zip.GZIPInputStream;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -451,11 +446,22 @@
final
- protected void defineRawInputStream( InputStream inputStream ) {
+ protected void defineRawInputStream( InputStream inputStream ) throws IOException {
if (_inputStream != null || _responseText != null) {
throw new IllegalStateException( "Must be called before response text is defined." );
}
- _inputStream = inputStream;
+
+ if (encodedUsingGZIP()) {
+ _inputStream = new GZIPInputStream( inputStream );
+ } else {
+ _inputStream = inputStream;
+ }
+ }
+
+
+ private boolean encodedUsingGZIP() {
+ String encoding = getHeaderField( "Content-Encoding" );
+ return encoding != null && encoding.indexOf( "gzip" ) >= 0;
}
|