You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2018/08/26 21:45:38 UTC

[maven-wagon] branch WAGON-528 created (now 8809d22)

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a change to branch WAGON-528
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git.


      at 8809d22  [WAGON-528] Extend and unify compression capabilities in HTTP (Lightweight) Wagon

This branch includes the following new commits:

     new 8809d22  [WAGON-528] Extend and unify compression capabilities in HTTP (Lightweight) Wagon

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-wagon] 01/01: [WAGON-528] Extend and unify compression capabilities in HTTP (Lightweight) Wagon

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch WAGON-528
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git

commit 8809d22af072cf566b7905bb1565cfd4b54a26ae
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sun Aug 26 23:44:23 2018 +0200

    [WAGON-528] Extend and unify compression capabilities in HTTP (Lightweight) Wagon
---
 .../apache/maven/wagon/http/HttpWagonTestCase.java | 80 ++++++++++++++++++++--
 .../wagon/providers/http/LightweightHttpWagon.java |  8 ++-
 .../wagon/shared/http/AbstractHttpClientWagon.java |  1 -
 .../wagon/providers/http/HttpClientWagonTest.java  | 10 +--
 .../providers/webdav/HttpClientWagonTest.java      | 11 +--
 5 files changed, 83 insertions(+), 27 deletions(-)

diff --git a/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java b/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java
index ee30271..b71ac55 100644
--- a/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java
+++ b/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java
@@ -74,6 +74,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.zip.DeflaterOutputStream;
 import java.util.zip.GZIPOutputStream;
 
 /**
@@ -583,7 +584,7 @@ public abstract class HttpWagonTestCase
             sourceFile.deleteOnExit();
 
             String resName = "gzip-res.txt";
-            String sourceContent = writeTestFileGzip( sourceFile, resName );
+            String sourceContent = writeTestFile( sourceFile, resName, "gzip" );
 
             wagon.connect( testRepository );
 
@@ -605,6 +606,56 @@ public abstract class HttpWagonTestCase
         }
     }
 
+    /* This test cannot be enabled because we cannot tell GzipFilter to compress with deflate only
+    public void testDeflateGet()
+            throws Exception
+        {
+            Server server = new Server( );
+
+            String localRepositoryPath = FileTestUtils.getTestOutputDir().toString();
+            ServletContextHandler root = new ServletContextHandler( ServletContextHandler.SESSIONS );
+            root.setResourceBase( localRepositoryPath );
+            ServletHolder servletHolder = new ServletHolder( new DefaultServlet() );
+            root.addServlet( servletHolder, "/*" );
+            FilterHolder filterHolder = new FilterHolder( new GzipFilter() );
+            root.addFilter( filterHolder, "/deflate/*", EnumSet.of( DispatcherType.REQUEST ) );
+            addConnector( server );
+            server.setHandler( root );
+            server.start();
+
+            try
+            {
+                Wagon wagon = getWagon();
+
+                Repository testRepository = new Repository( "id", getRepositoryUrl( server ) );
+
+                File sourceFile = new File( localRepositoryPath + "/deflate" );
+
+                sourceFile.deleteOnExit();
+
+                String resName = "deflate-res.txt";
+                String sourceContent = writeTestFile( sourceFile, resName, null );
+
+                wagon.connect( testRepository );
+
+                File destFile = FileTestUtils.createUniqueFile( getName(), getName() );
+
+                destFile.deleteOnExit();
+
+                wagon.get( "deflate/" + resName, destFile );
+
+                wagon.disconnect();
+
+                String destContent = FileUtils.fileRead( destFile );
+
+                assertEquals( sourceContent, destContent );
+            }
+            finally
+            {
+                server.stop();
+            }
+        }*/
+
     public void testProxiedRequest()
         throws Exception
     {
@@ -1546,7 +1597,7 @@ public abstract class HttpWagonTestCase
     }
 
 
-    private String writeTestFileGzip( File parent, String child )
+    private String writeTestFile( File parent, String child, String compressionType )
         throws IOException
     {
         File file = new File( parent, child );
@@ -1562,15 +1613,32 @@ public abstract class HttpWagonTestCase
             out.close();
         }
 
-        file = new File( parent, child + ".gz" );
+        String ext = "";
+        if ( "gzip".equals( compressionType ) )
+        {
+            ext = ".gz";
+        }
+        if ( "deflate".equals( compressionType ) )
+        {
+            ext = ".deflate";
+        }
+
+        file = new File( parent, child + ext );
         file.deleteOnExit();
         String content;
         out = new FileOutputStream( file );
-        out = new GZIPOutputStream( out );
+        if ( "gzip".equals( compressionType ) )
+        {
+            out = new GZIPOutputStream( out );
+        }
+        if ( "deflate".equals( compressionType ) )
+        {
+            out = new DeflaterOutputStream( out );
+        }
         try
         {
-            // write out different data than non-gz file, so we can
-            // assert the gz version was returned
+            // write out different data than non-compressed file, so we can
+            // assert the compressed version was returned
             content = file.getAbsolutePath();
             out.write( content.getBytes() );
         }
diff --git a/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java b/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java
index b22de62..50fc28a 100644
--- a/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java
+++ b/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java
@@ -50,6 +50,7 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
+import java.util.zip.DeflaterInputStream;
 import java.util.zip.GZIPInputStream;
 
 /**
@@ -119,7 +120,7 @@ public class LightweightHttpWagon
                 URL url = new URL( visitingUrl );
                 HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection( this.proxy );
 
-                urlConnection.setRequestProperty( "Accept-Encoding", "gzip" );
+                urlConnection.setRequestProperty( "Accept-Encoding", "gzip,deflate" );
                 if ( !useCache )
                 {
                     urlConnection.setRequestProperty( "Pragma", "no-cache" );
@@ -148,6 +149,11 @@ public class LightweightHttpWagon
                 {
                     is = new GZIPInputStream( is );
                 }
+                boolean isDeflated = contentEncoding != null && "deflate".equalsIgnoreCase( contentEncoding );
+                if ( isDeflated )
+                {
+                    is = new DeflaterInputStream( is );
+                }
                 inputData.setInputStream( is );
                 resource.setLastModified( urlConnection.getLastModified() );
                 resource.setContentLength( urlConnection.getContentLength() );
diff --git a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
index 3146909..097167f 100755
--- a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
+++ b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
@@ -930,7 +930,6 @@ public abstract class AbstractHttpClientWagon
             method.addHeader( "Cache-store", "no-store" );
             method.addHeader( "Pragma", "no-cache" );
             method.addHeader( "Expires", "0" );
-            method.addHeader( "Accept-Encoding", "gzip" );
         }
 
         if ( httpHeaders != null )
diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
index 57552f4..bf15e67 100755
--- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
+++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
@@ -71,7 +71,7 @@ public class HttpClientWagonTest
         // method.addRequestHeader( "Cache-store", "no-store" );
         // method.addRequestHeader( "Pragma", "no-cache" );
         // method.addRequestHeader( "Expires", "0" );
-        // method.addRequestHeader( "Accept-Encoding", "gzip" );
+        // "Accept-Encoding" is automatically set by HttpClient at runtime
 
         Header header = method.getFirstHeader( "Cache-control" );
         assertNotNull( header );
@@ -88,10 +88,6 @@ public class HttpClientWagonTest
         header = method.getFirstHeader( "Expires" );
         assertNotNull( header );
         assertEquals( "0", header.getValue() );
-
-        header = method.getFirstHeader( "Accept-Encoding" );
-        assertNotNull( header );
-        assertEquals( "gzip", header.getValue() );
     }
 
     public void testTurnOffDefaultHeaders()
@@ -110,7 +106,6 @@ public class HttpClientWagonTest
         // method.addRequestHeader( "Cache-store", "no-store" );
         // method.addRequestHeader( "Pragma", "no-cache" );
         // method.addRequestHeader( "Expires", "0" );
-        // method.addRequestHeader( "Accept-Encoding", "gzip" );
 
         Header header = method.getFirstHeader( "Cache-control" );
         assertNull( header );
@@ -123,9 +118,6 @@ public class HttpClientWagonTest
 
         header = method.getFirstHeader( "Expires" );
         assertNull( header );
-
-        header = method.getFirstHeader( "Accept-Encoding" );
-        assertNull( header );
     }
 
     private static final class TestWagon
diff --git a/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/HttpClientWagonTest.java b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/HttpClientWagonTest.java
index 7b8583c..177774b 100644
--- a/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/HttpClientWagonTest.java
+++ b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/HttpClientWagonTest.java
@@ -31,7 +31,6 @@ import org.apache.maven.wagon.authentication.AuthenticationException;
 import org.apache.maven.wagon.authentication.AuthenticationInfo;
 import org.apache.maven.wagon.proxy.ProxyInfo;
 import org.apache.maven.wagon.repository.Repository;
-import org.apache.maven.wagon.shared.http.AbstractHttpClientWagon;
 import org.apache.maven.wagon.shared.http.HttpConfiguration;
 import org.apache.maven.wagon.shared.http.HttpMethodConfiguration;
 import org.junit.Ignore;
@@ -97,7 +96,7 @@ public class HttpClientWagonTest
         // method.addRequestHeader( "Cache-store", "no-store" );
         // method.addRequestHeader( "Pragma", "no-cache" );
         // method.addRequestHeader( "Expires", "0" );
-        // method.addRequestHeader( "Accept-Encoding", "gzip" );
+        // "Accept-Encoding" is automatically set by HttpClient at runtime
 
         Header header = method.getFirstHeader( "Cache-control" );
         assertNotNull( header );
@@ -114,10 +113,6 @@ public class HttpClientWagonTest
         header = method.getFirstHeader( "Expires" );
         assertNotNull( header );
         assertEquals( "0", header.getValue() );
-
-        header = method.getFirstHeader( "Accept-Encoding" );
-        assertNotNull( header );
-        assertEquals( "gzip", header.getValue() );
     }
 
     public void testTurnOffDefaultHeaders()
@@ -136,7 +131,6 @@ public class HttpClientWagonTest
         // method.addRequestHeader( "Cache-store", "no-store" );
         // method.addRequestHeader( "Pragma", "no-cache" );
         // method.addRequestHeader( "Expires", "0" );
-        // method.addRequestHeader( "Accept-Encoding", "gzip" );
 
         Header header = method.getFirstHeader( "Cache-control" );
         assertNull( header );
@@ -149,9 +143,6 @@ public class HttpClientWagonTest
 
         header = method.getFirstHeader( "Expires" );
         assertNull( header );
-
-        header = method.getFirstHeader( "Accept-Encoding" );
-        assertNull( header );
     }
 
     @Ignore("not sure how to test this")