Merge remote-tracking branch 'origin/jetty-7' into jetty-8

Conflicts:
	VERSION.txt
	example-jetty-embedded/pom.xml
	jetty-aggregate/jetty-all-server/pom.xml
	jetty-aggregate/jetty-all/pom.xml
	jetty-aggregate/jetty-client/pom.xml
	jetty-aggregate/jetty-plus/pom.xml
	jetty-aggregate/jetty-server/pom.xml
	jetty-aggregate/jetty-servlet/pom.xml
	jetty-aggregate/jetty-webapp/pom.xml
	jetty-aggregate/jetty-websocket/pom.xml
	jetty-aggregate/pom.xml
	jetty-ajp/pom.xml
	jetty-annotations/pom.xml
	jetty-client/pom.xml
	jetty-continuation/pom.xml
	jetty-deploy/pom.xml
	jetty-distribution/pom.xml
	jetty-http-spi/pom.xml
	jetty-http/pom.xml
	jetty-io/pom.xml
	jetty-jaspi/pom.xml
	jetty-jmx/pom.xml
	jetty-jndi/pom.xml
	jetty-jsp/pom.xml
	jetty-monitor/pom.xml
	jetty-nested/pom.xml
	jetty-nosql/pom.xml
	jetty-osgi/jetty-osgi-boot-jsp/pom.xml
	jetty-osgi/jetty-osgi-boot-warurl/pom.xml
	jetty-osgi/jetty-osgi-boot/pom.xml
	jetty-osgi/jetty-osgi-httpservice/pom.xml
	jetty-osgi/pom.xml
	jetty-osgi/test-jetty-osgi-context/pom.xml
	jetty-osgi/test-jetty-osgi-webapp/pom.xml
	jetty-osgi/test-jetty-osgi/pom.xml
	jetty-overlay-deployer/pom.xml
	jetty-plus/pom.xml
	jetty-policy/pom.xml
	jetty-rewrite/pom.xml
	jetty-security/pom.xml
	jetty-server/pom.xml
	jetty-servlet/pom.xml
	jetty-servlets/pom.xml
	jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java
	jetty-spdy/pom.xml
	jetty-spdy/spdy-core/pom.xml
	jetty-spdy/spdy-jetty-http-webapp/pom.xml
	jetty-spdy/spdy-jetty-http/pom.xml
	jetty-spdy/spdy-jetty/pom.xml
	jetty-start/pom.xml
	jetty-util/pom.xml
	jetty-webapp/pom.xml
	jetty-websocket/pom.xml
	jetty-xml/pom.xml
	pom.xml
	test-continuation/pom.xml
	test-jetty-nested/pom.xml
	test-jetty-servlet/pom.xml
	test-jetty-webapp/pom.xml
	tests/pom.xml
	tests/test-integration/pom.xml
	tests/test-loginservice/pom.xml
	tests/test-sessions/pom.xml
	tests/test-sessions/test-hash-sessions/pom.xml
	tests/test-sessions/test-jdbc-sessions/pom.xml
	tests/test-sessions/test-mongodb-sessions/pom.xml
	tests/test-sessions/test-sessions-common/pom.xml
	tests/test-webapps/pom.xml
	tests/test-webapps/test-webapp-rfc2616/pom.xml
diff --git a/VERSION.txt b/VERSION.txt
index b2cc3a8..838f1d7 100644
--- a/VERSION.txt
+++ b/VERSION.txt
@@ -64,6 +64,31 @@
  + 402833 Test harness for global error page and hide exception message from
    reason string
 
+jetty-7.6.11.v20130520 - 20 May 2013
+ + 402844 STOP.PORT & STOP.KEY behaviour has changed
+ + 403281 jetty.sh waits for started or failure before returning
+ + 403513 jetty:run goal cannot be executed twice during the maven build
+ + 403570 Asynchronous Request Logging
+ + 404010 fix cast exception in mongodb session manager
+ + 404128 Add Vary headers rather than set them
+ + 404283 org.eclipse.jetty.util.Scanner.scanFile() dies with an NPE if
+   listFiles() returns null
+ + 404325 data constraint redirection does send default port
+ + 404517 Close connection if request received after half close
+ + 404789 Support IPv6 addresses in DoSFilter white list.
+ + 404958 Fixed Resource.newSystemResource striped / handling
+ + 405281 allow filemappedbuffers to not be used
+ + 405537 NPE in rendering JSP using SPDY and wrapped ServletRequest
+ + 406437 Digest Auth supports out of order nc
+ + 406923 CR line termination
+ + 407136 @PreDestroy called after Servlet.destroy()
+ + 407173 java.lang.IllegalStateException: null when using JDBCSessionManager
+ + 407976 JDBCSessionIdManager potentially leaves server in bad state after
+   startup
+ + 408077 HashSessionManager leaves file handles open after being stopped
+ + 408446 Multipart parsing issue with boundry and charset in ContentType
+   header
+
 jetty-7.6.10.v20130312 - 12 March 2013
  + 376273 Early EOF because of SSL Protocol Error on
    https://api-3t.paypal.com/nvp.
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/gzip/AbstractCompressedStream.java b/jetty-http/src/main/java/org/eclipse/jetty/http/gzip/AbstractCompressedStream.java
index 3094d3a..e1c805e 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/gzip/AbstractCompressedStream.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/gzip/AbstractCompressedStream.java
@@ -65,23 +65,32 @@
             doCompress();
     }
 
+    /* ------------------------------------------------------------ */
     /**
      * Reset buffer.
      */
     public void resetBuffer()
     {
-        if (_response.isCommitted())
+        if (_response.isCommitted() || _compressedOutputStream!=null )
             throw new IllegalStateException("Committed");
         _closed = false;
         _out = null;
         _bOut = null;
-        if (_compressedOutputStream != null)
-            _response.setHeader("Content-Encoding",null);
-        _compressedOutputStream = null;
         _doNotCompress = false;
     }
 
     /* ------------------------------------------------------------ */
+    public void setBufferSize(int bufferSize)
+    {
+        if (_bOut!=null && _bOut.getBuf().length<bufferSize)
+        {
+            ByteArrayOutputStream2 b = new ByteArrayOutputStream2(bufferSize);
+            b.write(_bOut.getBuf(),0,_bOut.size());
+            _bOut=b;
+        }
+    }
+    
+    /* ------------------------------------------------------------ */
     public void setContentLength()
     {
         if (_doNotCompress)
@@ -170,7 +179,7 @@
             if (_out == null || _bOut != null)
             {
                 long length=_wrapper.getContentLength();
-                if (length > 0 && length < _wrapper.getMinCompressSize())
+                if (length >= 0 && length < _wrapper.getMinCompressSize())
                     doNotCompress(false);
                 else
                     doCompress();
@@ -359,4 +368,5 @@
      */
     protected abstract DeflaterOutputStream createStream() throws IOException;
 
+
 }
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/gzip/CompressedResponseWrapper.java b/jetty-http/src/main/java/org/eclipse/jetty/http/gzip/CompressedResponseWrapper.java
index 0ddf819..f23799c 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/gzip/CompressedResponseWrapper.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/gzip/CompressedResponseWrapper.java
@@ -107,6 +107,8 @@
     public void setBufferSize(int bufferSize)
     {
         _bufferSize = bufferSize;
+        if (_compressedStream!=null)
+            _compressedStream.setBufferSize(bufferSize);
     }
 
     /* ------------------------------------------------------------ */
@@ -127,18 +129,21 @@
     {
         super.setContentType(ct);
     
-        if (ct!=null)
+        if (!_noCompression)
         {
-            int colon=ct.indexOf(";");
-            if (colon>0)
-                ct=ct.substring(0,colon);
-        }
-    
-        if ((_compressedStream==null || _compressedStream.getOutputStream()==null) && 
-            (_mimeTypes==null && ct!=null && ct.contains("gzip") ||
-             _mimeTypes!=null && (ct==null||!_mimeTypes.contains(StringUtil.asciiToLowerCase(ct)))))
-        {
-            noCompression();
+            if (ct!=null)
+            {
+                int colon=ct.indexOf(";");
+                if (colon>0)
+                    ct=ct.substring(0,colon);
+            }
+
+            if ((_compressedStream==null || _compressedStream.getOutputStream()==null) && 
+                    (_mimeTypes==null && ct!=null && ct.contains("gzip") ||
+                    _mimeTypes!=null && (ct==null||!_mimeTypes.contains(StringUtil.asciiToLowerCase(ct)))))
+            {
+                noCompression();
+            }
         }
     }
 
@@ -173,7 +178,10 @@
     @Override
     public void setContentLength(int length)
     {
-        setContentLength((long)length);
+        if (_noCompression)
+            super.setContentLength(length);
+        else
+            setContentLength((long)length);
     }
     
     /* ------------------------------------------------------------ */
@@ -311,6 +319,8 @@
      */
     public void noCompression()
     {
+        if (!_noCompression)
+            setDeferredHeaders();
         _noCompression=true;
         if (_compressedStream!=null)
         {
@@ -335,6 +345,25 @@
             _writer.flush();
         if (_compressedStream!=null)
             _compressedStream.finish();
+        else 
+            setDeferredHeaders();
+    }
+
+    /* ------------------------------------------------------------ */
+    private void setDeferredHeaders()
+    {
+        if (!isCommitted())
+        {
+            if (_contentLength>=0)
+            {
+                if (_contentLength < Integer.MAX_VALUE)
+                    super.setContentLength((int)_contentLength);
+                else
+                    super.setHeader("Content-Length",Long.toString(_contentLength));
+            }
+            if(_etag!=null)
+                super.setHeader("ETag",_etag);
+        }
     }
     
     /* ------------------------------------------------------------ */
@@ -344,7 +373,9 @@
     @Override
     public void setHeader(String name, String value)
     {
-        if ("content-length".equalsIgnoreCase(name))
+        if (_noCompression)
+            super.setHeader(name,value);
+        else if ("content-length".equalsIgnoreCase(name))
         {
             setContentLength(Long.parseLong(value));
         }
@@ -370,7 +401,7 @@
     @Override
     public boolean containsHeader(String name)
     {
-        if ("etag".equalsIgnoreCase(name) && _etag!=null)
+        if (!_noCompression && "etag".equalsIgnoreCase(name) && _etag!=null)
             return true;
         return super.containsHeader(name);
     }
@@ -385,10 +416,7 @@
         if (_compressedStream==null)
         {
             if (getResponse().isCommitted() || _noCompression)
-            {
-                setContentLength(_contentLength);
                 return getResponse().getOutputStream();
-            }
             
             _compressedStream=newCompressedStream(_request,(HttpServletResponse)getResponse());
         }
@@ -411,10 +439,7 @@
                 throw new IllegalStateException("getOutputStream() called");
             
             if (getResponse().isCommitted() || _noCompression)
-            {
-                setContentLength(_contentLength);
                 return getResponse().getWriter();
-            }
             
             _compressedStream=newCompressedStream(_request,(HttpServletResponse)getResponse());
             _writer=newWriter(_compressedStream,getCharacterEncoding());
diff --git a/jetty-osgi/jetty-osgi-boot-logback/pom.xml b/jetty-osgi/jetty-osgi-boot-logback/pom.xml
deleted file mode 100644
index f1985b7..0000000
--- a/jetty-osgi/jetty-osgi-boot-logback/pom.xml
+++ /dev/null
@@ -1,127 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <parent>
-    <groupId>org.eclipse.jetty.osgi</groupId>
-    <artifactId>jetty-osgi-project</artifactId>
-    <version>7.6.11-SNAPSHOT</version>
-    <relativePath>../pom.xml</relativePath>
-  </parent>
-  <modelVersion>4.0.0</modelVersion>
-  <artifactId>jetty-osgi-boot-logback</artifactId>
-  <name>Jetty :: OSGi :: Boot Logback</name>
-  <description>Jetty OSGi Boot Logback bundle</description>
-  <url>http://www.eclipse.org/jetty</url>
-  <properties>
-    <bundle-symbolic-name>${project.groupId}.boot.logback</bundle-symbolic-name>
-  </properties>
-  <dependencies>
-    <dependency>
-      <groupId>org.eclipse.jetty.osgi</groupId>
-      <artifactId>jetty-osgi-boot</artifactId>
-      <version>${project.version}</version>
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
-    	<groupId>org.eclipse.osgi</groupId>
-    	<artifactId>org.eclipse.osgi</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.eclipse.jetty</groupId>
-      <artifactId>jetty-webapp</artifactId>
-    </dependency>
-    <dependency>
-        <groupId>org.eclipse.osgi</groupId>
-        <artifactId>org.eclipse.osgi.services</artifactId>
-    </dependency>
-      <dependency>
-        <groupId>org.slf4j</groupId>
-        <artifactId>slf4j-api</artifactId>
-      </dependency>
-      <dependency>
-        <groupId>org.slf4j</groupId>
-        <artifactId>jcl-over-slf4j</artifactId>
-      </dependency>
-      <dependency>
-        <groupId>org.slf4j</groupId>
-        <artifactId>log4j-over-slf4j</artifactId>
-      </dependency>
-      <dependency>
-        <groupId>ch.qos.logback</groupId>
-        <artifactId>logback-core</artifactId>
-      </dependency>
-      <dependency>
-        <groupId>ch.qos.logback</groupId>
-        <artifactId>logback-classic</artifactId>
-      </dependency>
-  </dependencies>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-jar-plugin</artifactId>
-        <executions>
-          <execution>
-            <id>artifact-jar</id>
-            <goals>
-              <goal>jar</goal>
-            </goals>
-          </execution>
-          <execution>
-            <id>test-jar</id>
-            <goals>
-              <goal>test-jar</goal>
-            </goals>
-          </execution>
-        </executions>
-        <configuration>
-          <archive>
-            <manifestFile>target/classes/META-INF/MANIFEST.MF</manifestFile>
-          </archive>
-        </configuration>
-      </plugin>
-      <plugin>
-          <groupId>org.apache.felix</groupId>
-          <artifactId>maven-bundle-plugin</artifactId>
-          <extensions>true</extensions>
-          <executions>
-              <execution>
-                  <id>bundle-manifest</id>
-                  <phase>process-classes</phase>
-                  <goals>
-                      <goal>manifest</goal>
-                  </goals>
-              </execution>
-          </executions>
-          <configuration>
-              <instructions>
-                <Bundle-SymbolicName>org.eclipse.jetty.osgi.boot.logback;singleton:=true</Bundle-SymbolicName>
-                <Bundle-Name>Jetty-OSGi-Logback Integration</Bundle-Name>
-                <Fragment-Host>org.eclipse.jetty.osgi.boot</Fragment-Host>
-                <Import-Package>
-ch.qos.logback.access.jetty;version="[0.9,1.1)";resolution:=optional,
-ch.qos.logback.access.jetty.v7;version="[0.9,1.1)";resolution:=optional,
-ch.qos.logback.*;version="[0.9,1.1)",
-org.osgi.framework.*,
-org.slf4j.*,
-*;resolution:=optional
-                </Import-Package>
-                <Export-Package>
-!org.eclipse.jetty.osgi.boot.logback.internal.*,
-org.eclipse.jetty.osgi.boot.logback.*;version="${parsedVersion.osgiVersion}"
-                </Export-Package>
-                <_nouses>true</_nouses>
-              </instructions>
-          </configuration>
-      </plugin>
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>findbugs-maven-plugin</artifactId>
-        <configuration>
-          <onlyAnalyze>org.eclipse.jetty.osgi.boot.logback.*</onlyAnalyze>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
-
-
-</project>
diff --git a/jetty-osgi/jetty-osgi-equinoxtools/pom.xml b/jetty-osgi/jetty-osgi-equinoxtools/pom.xml
deleted file mode 100644
index 1db3f81..0000000
--- a/jetty-osgi/jetty-osgi-equinoxtools/pom.xml
+++ /dev/null
@@ -1,121 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <parent>
-    <groupId>org.eclipse.jetty.osgi</groupId>
-    <artifactId>jetty-osgi-project</artifactId>
-    <version>7.6.11-SNAPSHOT</version>
-    <relativePath>../pom.xml</relativePath>
-  </parent>
-  <modelVersion>4.0.0</modelVersion>
-  <artifactId>jetty-osgi-equinoxtools</artifactId>
-  <name>Jetty :: OSGi :: Example Equinox Tools</name>
-  <description>Jetty OSGi Example Equinox Tools</description>
-  <url>http://www.eclipse.org/jetty</url>
-  <properties>
-    <bundle-symbolic-name>${project.groupId}.equinoxtools</bundle-symbolic-name>
-  </properties>
-  <dependencies>
-    <dependency>
-      <groupId>org.eclipse.jetty</groupId>
-      <artifactId>jetty-webapp</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.eclipse.jetty</groupId>
-      <artifactId>jetty-continuation</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.eclipse.jetty</groupId>
-      <artifactId>jetty-websocket</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.eclipse.jetty</groupId>
-      <artifactId>jetty-servlet</artifactId>
-    </dependency>
-    <dependency>
-    	<groupId>org.eclipse.osgi</groupId>
-    	<artifactId>org.eclipse.osgi</artifactId>
-    </dependency>
-    <dependency>
-        <groupId>org.eclipse.osgi</groupId>
-        <artifactId>org.eclipse.osgi.services</artifactId>
-    </dependency>
-  </dependencies>
-
-   <build>
-    <plugins>
-      <plugin>
-        <artifactId>maven-antrun-plugin</artifactId>
-        <executions>
-          <execution>
-            <phase>process-resources</phase>
-            <configuration>
-              <tasks>
-                <copy todir="target/classes/equinoxconsole">
-                    <fileset dir="equinoxconsole" />
-                </copy>
-              </tasks>
-            </configuration>
-            <goals>
-              <goal>run</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-jar-plugin</artifactId>
-        <executions>
-          <execution>
-            <id>artifact-jar</id>
-            <goals>
-              <goal>jar</goal>
-            </goals>
-          </execution>
-          <execution>
-            <id>test-jar</id>
-            <goals>
-              <goal>test-jar</goal>
-            </goals>
-          </execution>
-        </executions>
-        <configuration>
-          <archive>
-            <manifestFile>target/classes/META-INF/MANIFEST.MF</manifestFile>
-          </archive>
-        </configuration>
-      </plugin>
-      <plugin>
-          <groupId>org.apache.felix</groupId>
-          <artifactId>maven-bundle-plugin</artifactId>
-          <extensions>true</extensions>
-          <executions>
-              <execution>
-                  <id>bundle-manifest</id>
-                  <phase>process-classes</phase>
-                  <goals>
-                      <goal>manifest</goal> 
-                  </goals>
-              </execution>
-          </executions>
-          <configuration>
-              <instructions>
-                <Bundle-SymbolicName>org.eclipse.jetty.osgi.equinoxtools</Bundle-SymbolicName>
-                <Bundle-Name>Console</Bundle-Name>
-                <Bundle-Activator>org.eclipse.jetty.osgi.equinoxtools.WebEquinoxToolsActivator</Bundle-Activator>
-                <Export-Package>org.eclipse.jetty.osgi.equinoxtools;x-internal:=true;version="${parsedVersion.osgiVersion}",
-                                org.eclipse.jetty.osgi.equinoxtools.console;x-internal:=true;version="${parsedVersion.osgiVersion}"
-                </Export-Package>
-                <_nouses>true</_nouses>
-              </instructions>
-          </configuration>
-      </plugin>
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>findbugs-maven-plugin</artifactId>
-        <configuration>
-          <onlyAnalyze>org.eclipse.jetty.osgi.equinoxtools.*</onlyAnalyze>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
-
-</project>
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java
index 0b1d218..885a01d 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java
@@ -33,7 +33,10 @@
 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.testing.HttpTester;
 import org.eclipse.jetty.toolchain.test.TestingDir;
+import org.hamcrest.Matchers;
+import org.junit.Assert;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -131,7 +134,8 @@
         try
         {
             tester.start();
-            tester.assertIsResponseNotGzipCompressed("GET",testfile.getName(),filesize,HttpStatus.OK_200);
+            HttpTester response = tester.assertIsResponseNotGzipCompressed("GET",testfile.getName(),filesize,HttpStatus.OK_200);
+            Assert.assertThat(response.getHeader("ETAG"),Matchers.startsWith("w/etag-"));
         }
         finally
         {
@@ -143,6 +147,15 @@
      * Tests gzip compression of a small size file
      */
     @Test
+    public void testEmpty() throws Exception
+    {
+        assertIsNotGzipCompressed("empty.txt",0);
+    }
+    
+    /**
+     * Tests gzip compression of a small size file
+     */
+    @Test
     public void testIsGzipCompressedSmall() throws Exception
     {
         assertIsGzipCompressed("file-small.txt",SMALL);
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterDefaultTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterDefaultTest.java
index c420c4c..f6db638 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterDefaultTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterDefaultTest.java
@@ -79,6 +79,7 @@
         protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
         {
             resp.setStatus(_status);
+            resp.setHeader("ETag","W/\"204\"");
         }
         
     }
@@ -141,11 +142,40 @@
         @Override
         public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException,ServletException
         {
+            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)));
+                resp.setContentType(getServletContext().getMimeType(uri.substring(0,uri.length()-9)));
+            }
+            
             doGet(req,resp);
         }
     }
     
+   
     
+    @Test
+    public void testIsGzipCompressedEmpty() throws Exception
+    {
+        GzipTester tester = new GzipTester(testingdir, compressionType);
+
+        // Test content that is smaller than the buffer.
+        tester.prepareServerFile("empty.txt",0);
+        
+        FilterHolder holder = tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class);
+        holder.setInitParameter("mimeTypes","text/plain");
+
+        try
+        {
+            tester.start();
+            HttpTester http = tester.assertIsResponseNotGzipCompressed("GET","empty.txt",0,200);
+        }
+        finally
+        {
+            tester.stop();
+        }
+    }
     
     @Test
     public void testIsGzipCompressedTiny() throws Exception
@@ -242,7 +272,7 @@
             tester.stop();
         }
     }
-    
+
     @Test
     public void testIsNotGzipCompressedWithQ() throws Exception
     {
@@ -267,7 +297,7 @@
     }
     
     @Test
-    public void testIsNotGzipCompressed() throws Exception
+    public void testIsNotGzipCompressedByContentType() throws Exception
     {
         GzipTester tester = new GzipTester(testingdir, compressionType);
 
@@ -290,6 +320,29 @@
     }
     
     @Test
+    public void testIsNotGzipCompressedByDeferredContentType() throws Exception
+    {
+        GzipTester tester = new GzipTester(testingdir, compressionType);
+
+        int filesize = CompressedResponseWrapper.DEFAULT_BUFFER_SIZE * 4;
+        tester.prepareServerFile("file.mp3.deferred",filesize);
+        
+        FilterHolder holder = tester.setContentServlet(GetServlet.class);
+        holder.setInitParameter("mimeTypes","text/plain");
+
+        try
+        {
+            tester.start();
+            HttpTester http = tester.assertIsResponseNotGzipCompressed("GET","file.mp3.deferred", filesize, HttpStatus.OK_200);
+            Assert.assertNull(http.getHeader("Vary"));
+        }
+        finally
+        {
+            tester.stop();
+        }
+    }
+    
+    @Test
     public void testIsNotGzipCompressedHttpStatus() throws Exception
     { 
         GzipTester tester = new GzipTester(testingdir, compressionType);
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java
index c4ee733..7a09b57 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java
@@ -56,6 +56,7 @@
 import org.eclipse.jetty.toolchain.test.IO;
 import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
 import org.eclipse.jetty.toolchain.test.TestingDir;
+import org.hamcrest.Matchers;
 import org.junit.Assert;
 
 public class GzipTester
@@ -110,6 +111,8 @@
         else
             Assert.assertThat("Response.header[Content-Encoding]", response.getHeader("Content-Encoding"),containsString(compressionType.substring(0,qindex)));
 
+        Assert.assertThat(response.getHeader("ETag"),Matchers.startsWith("W/"));
+        
         // Assert that the decompressed contents are what we expect.
         File serverFile = testdir.getFile(serverFilename);
         String expected = IO.readToString(serverFile);
@@ -191,6 +194,8 @@
         Assert.assertThat(prefix + ".header[Content-Type] (should have a Content-Type associated with it)",response.getHeader("Content-Type"),notNullValue());
         Assert.assertThat(prefix + ".header[Content-Type]",response.getHeader("Content-Type"),is(expectedContentType));
 
+        Assert.assertThat(response.getHeader("ETAG"),Matchers.startsWith("w/etag-"));
+        
         ByteArrayInputStream bais = null;
         DigestOutputStream digester = null;
         try
@@ -315,6 +320,10 @@
             int serverLength = Integer.parseInt(response.getHeader("Content-Length"));
             Assert.assertThat("Response.header[Content-Length]",serverLength,is(expectedFilesize));
         }
+        
+        if (status>=200 && status<300)
+            Assert.assertThat(response.getHeader("ETAG"),Matchers.startsWith("W/"));
+            
     }
 
     private HttpTester executeRequest(String method,String uri) throws IOException, Exception
@@ -347,11 +356,11 @@
         ByteArrayOutputStream out = null;
         try
         {
-            in = new ByteArrayInputStream(response.getContentBytes());
-            out = new ByteArrayOutputStream();
-            IO.copy(in,out);
-
-            actual = out.toString(encoding);
+            byte[] content=response.getContentBytes();
+            if (content!=null)  
+                actual=new String(response.getContentBytes(),encoding);
+            else
+                actual="";
         }
         finally
         {
@@ -434,7 +443,7 @@
         finally
         {
             IO.close(in);
-            IO.close(fos);
+            IO.close(fos);            
         }
     }
 
@@ -466,6 +475,7 @@
         servletTester.setResourceBase(testdir.getDir().getCanonicalPath());
         ServletHolder servletHolder = servletTester.addServlet(servletClass,"/");
         servletHolder.setInitParameter("baseDir",testdir.getDir().getAbsolutePath());
+        servletHolder.setInitParameter("etags","true");
         FilterHolder holder = servletTester.addFilter(gzipFilterClass,"/*",EnumSet.allOf(DispatcherType.class));
         holder.setInitParameter("vary","Accept-Encoding");
         return holder;
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthStreamTypeWrite.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthStreamTypeWrite.java
index 72fa262..c318fac 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthStreamTypeWrite.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthStreamTypeWrite.java
@@ -59,6 +59,7 @@
             response.setContentType("text/plain");
         else if (fileName.endsWith("mp3"))
             response.setContentType("audio/mpeg");
+        response.setHeader("ETag","w/etag-"+fileName);
 
         out.write(dataBytes);
     }
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthTypeStreamWrite.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthTypeStreamWrite.java
index 84a6ce3..227fc9f 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthTypeStreamWrite.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthTypeStreamWrite.java
@@ -57,6 +57,7 @@
             response.setContentType("text/plain");
         else if (fileName.endsWith("mp3"))
             response.setContentType("audio/mpeg");
+        response.setHeader("ETag","w/etag-"+fileName);
 
         ServletOutputStream out = response.getOutputStream();
         out.write(dataBytes);
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamLengthTypeWrite.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamLengthTypeWrite.java
index a504688..b54fcdc 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamLengthTypeWrite.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamLengthTypeWrite.java
@@ -59,6 +59,7 @@
             response.setContentType("text/plain");
         else if (fileName.endsWith("mp3"))
             response.setContentType("audio/mpeg");
+        response.setHeader("ETag","w/etag-"+fileName);
 
         out.write(dataBytes);
     }
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamTypeLengthWrite.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamTypeLengthWrite.java
index 7b412d0..54ca278 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamTypeLengthWrite.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamTypeLengthWrite.java
@@ -57,6 +57,7 @@
             response.setContentType("text/plain");
         else if (fileName.endsWith("mp3"))
             response.setContentType("audio/mpeg");
+        response.setHeader("ETag","w/etag-"+fileName);
 
         response.setContentLength(dataBytes.length);
 
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeLengthStreamWrite.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeLengthStreamWrite.java
index 1ae34f0..2ae83ee 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeLengthStreamWrite.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeLengthStreamWrite.java
@@ -55,6 +55,7 @@
             response.setContentType("text/plain");
         else if (fileName.endsWith("mp3"))
             response.setContentType("audio/mpeg");
+        response.setHeader("ETag","w/etag-"+fileName);
 
         response.setContentLength(dataBytes.length);
 
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeStreamLengthWrite.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeStreamLengthWrite.java
index 0d1def6..67c1e72 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeStreamLengthWrite.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeStreamLengthWrite.java
@@ -55,6 +55,7 @@
             response.setContentType("text/plain");
         else if (fileName.endsWith("mp3"))
             response.setContentType("audio/mpeg");
+        response.setHeader("ETag","w/etag-"+fileName);
 
         ServletOutputStream out = response.getOutputStream();
 
diff --git a/test-jetty-servlet/src/main/java/org/eclipse/jetty/testing/HttpTester.java b/test-jetty-servlet/src/main/java/org/eclipse/jetty/testing/HttpTester.java
index 1621a7e..8d85847 100644
--- a/test-jetty-servlet/src/main/java/org/eclipse/jetty/testing/HttpTester.java
+++ b/test-jetty-servlet/src/main/java/org/eclipse/jetty/testing/HttpTester.java
@@ -599,4 +599,12 @@
         
     }
 
+    @Override
+    public String toString()
+    {
+        if (_method!=null)
+            return super.toString()+" "+_method+" "+_uri+" "+_version+"\n"+_fields.toString();
+
+        return super.toString()+" HTTP/1.1 "+_status+" "+_reason+"\n"+_fields.toString();
+    }
 }