ZeroCopyConsumer: preserve content encoding
Contributed by Dmitry Potapov <dpotapov at yandex-team.ru>

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpasyncclient/trunk@1626969 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/ZeroCopyConsumer.java b/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/ZeroCopyConsumer.java
index b1227ce..24a556f 100644
--- a/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/ZeroCopyConsumer.java
+++ b/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/ZeroCopyConsumer.java
@@ -32,6 +32,7 @@
 import java.io.RandomAccessFile;
 import java.nio.channels.FileChannel;
 
+import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.entity.ContentType;
@@ -60,6 +61,7 @@
 
     private HttpResponse response;
     private ContentType contentType;
+    private Header contentEncoding;
     private FileChannel fileChannel;
     private long idx = -1;
 
@@ -81,6 +83,7 @@
     protected void onEntityEnclosed(
             final HttpEntity entity, final ContentType contentType) throws IOException {
         this.contentType = contentType;
+        this.contentEncoding = entity.getContentEncoding();
         this.fileChannel = this.accessfile.getChannel();
         this.idx = 0;
     }
@@ -118,7 +121,9 @@
 
     @Override
     protected T buildResult(final HttpContext context) throws Exception {
-        this.response.setEntity(new FileEntity(this.file, this.contentType));
+        final FileEntity entity = new FileEntity(this.file, this.contentType);
+        entity.setContentEncoding(this.contentEncoding);
+        this.response.setEntity(entity);
         return process(this.response, this.file, this.contentType);
     }