package jenkins.plugins.http_request;

import java.io.IOException;
import java.io.Serializable;

import org.apache.http.HttpResponse;
import org.apache.http.HttpEntity;
import org.apache.http.util.EntityUtils;

import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;

/**
 * A container for the Http Response.
 * The container is returned as is to the Pipeline. For the normal
 * plugin, the container is consumed internally (since it cannot be returned).
 */
class ResponseContentSupplier implements Serializable {

    private static final long serialVersionUID = 1L;

    private transient HttpResponse response;
    private String content;
    private int status;

    public ResponseContentSupplier(HttpResponse response) {
        this.response = response;
        this.status = response.getStatusLine().getStatusCode();
        this.content = getContent();
    }

    @Whitelisted
    public int getStatus() {
        return status;
    }

    @Whitelisted
    public String getContent() {
        if (content != null) {
            return content;
        }
        try {
            HttpEntity entity = response.getEntity();
            if (entity == null) {
                return null;
            }
            content = EntityUtils.toString(entity);
            EntityUtils.consume(response.getEntity());
            return content;
        } catch (IOException e) {
            return null;
        }
    }

    @Override
    public String toString() {
        return "Status: "+status+", Response: "+content;
    }
}

@@ -588,53 +588,8 @@
 L;%0A%0A
-    private transient HttpResponse response;%0A
     
@@ -608,24 +608,24 @@
 ng content;%0A
+
     private 
@@ -701,42 +701,8 @@
 ) %7B%0A
-        this.response = response;%0A
     
@@ -773,34 +773,27 @@
     
-this.content = getContent(
+setContent(response
 );%0A 
@@ -936,68 +936,83 @@
     
-if (content != null) %7B
+return content;
 %0A    
+%7D%0A%0A
     
-    return content;%0A        %7D
+private void setContent(HttpResponse response) %7B
 %0A   
@@ -1124,37 +1124,32 @@
           return
- null
 ;%0A            %7D%0A
@@ -1259,36 +1259,8 @@
 ));%0A
-            return content;%0A
     
@@ -1305,19 +1305,75 @@
     
-return null
+content = %22IOException while reading HttpResponse: %22+e.getMessage()
 ;%0A  

Remove HttpResponse member from ResponseContentSupplier