package com.github.ignition.support.http.gzip;

import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseInterceptor;
import org.apache.http.protocol.HttpContext;

import com.github.ignition.support.http.IgnitedHttp;

/**
 * Simple {@link HttpResponseInterceptor} that inflates response if GZIP encoding header.
 */
public class GzipHttpResponseInterceptor implements HttpResponseInterceptor {

    @Override
    public void process(final HttpResponse response, final HttpContext context) {
        // Inflate any responses compressed with gzip
        final HttpEntity entity = response.getEntity();
        final Header encoding = entity.getContentEncoding();
        if (encoding != null) {
            for (HeaderElement element : encoding.getElements()) {
                if (element.getName().equalsIgnoreCase(IgnitedHttp.ENCODING_GZIP)) {
                    response.setEntity(new GzipInflatingEntity(response.getEntity()));
                    break;
                }
            }
        }
    }

}

@@ -709,24 +709,58 @@
 etEntity();%0A
+        if (entity != null) %7B%0A    
         fina
@@ -804,24 +804,28 @@
 Encoding();%0A
+    
         if (
@@ -856,16 +856,20 @@
         
+    
 for (Hea
@@ -911,24 +911,28 @@
 ements()) %7B%0A
+    
             
@@ -1024,16 +1024,20 @@
         
+  
+  
 response
@@ -1119,15 +1119,41 @@
     
+    
 break;%0A
+                    %7D%0A
     

Check if http entity is null and don't do anything if it is.