Repository: zaproxy/zaproxy
Issue: Loss of new line chars for GZIP HTTP responses returned by the API

### Describe the bug

When the content encoding of a message response is gzip the method `httpMessageToSet` of `ApiResponseConversionUtils.java` reads the unzipped content line by line and forgets to add the new line chars to the string is going to add to the ApiResponseConversionUtils. The code where this happen is:
```java
if (HttpHeader.GZIP.equals(
                msg.getResponseHeader().getHeader(HttpHeader.CONTENT_ENCODING))) {
            // Uncompress gziped content
            try (ByteArrayInputStream bais =
                            new ByteArrayInputStream(msg.getResponseBody().getBytes());
                    GZIPInputStream gis = new GZIPInputStream(bais);
                    InputStreamReader isr = new InputStreamReader(gis);
                    BufferedReader br = new BufferedReader(isr); ) {
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = br.readLine()) != null) {
                    sb.append(line);
                }
                map.put("responseBody", sb.toString());
            } catch (IOException e) {
                LOGGER.error("Unable to uncompress gzip content: " + e.getMessage(), e);
                map.put("responseBody", msg.getResponseBody().toString());
            }
        } else {
            map.put("responseBody", msg.getResponseBody().toString());
        }
```


### Steps to reproduce the behavior

1. Make a request to a server that responds with gzip encoding using the ZAP API ( `/JSON/core/action/accessUrl/`)
2. On the API request result check if the response has new line chars.

### Expected behavior

The response should have new line characters.

### Software versions

The main branch

### Screenshots

_No response_

### Errors from the zap.log file

_No response_

### Additional context

_No response_

### Would you like to help fix this issue?

- [X] Yes

Changed files:
zap/src/main/java/org/zaproxy/zap/extension/api/ApiResponseConversionUtils.java
zap/src/test/java/org/zaproxy/zap/extension/api/ApiResponseConversionUtilsUnitTest.java

diff --git a/zap/src/main/java/org/zaproxy/zap/extension/api/ApiResponseConversionUtils.java b/zap/src/main/java/org/zaproxy/zap/extension/api/ApiResponseConversionUtils.java
index 8a92d3441..1d22fde75 100644
--- a/zap/src/main/java/org/zaproxy/zap/extension/api/ApiResponseConversionUtils.java
+++ b/zap/src/main/java/org/zaproxy/zap/extension/api/ApiResponseConversionUtils.java
@@ -19,16 +19,11 @@
  */
 package org.zaproxy.zap.extension.api;
 
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.zip.GZIPInputStream;
 import net.sf.json.JSON;
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
@@ -37,7 +32,6 @@ import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.parosproxy.paros.db.DatabaseException;
 import org.parosproxy.paros.model.HistoryReference;
-import org.parosproxy.paros.network.HttpHeader;
 import org.parosproxy.paros.network.HttpMessage;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -89,28 +83,7 @@ public final class ApiResponseConversionUtils {
         map.put("requestHeader", msg.getRequestHeader().toString());
         map.put("requestBody", msg.getRequestBody().toString());
         map.put("responseHeader", msg.getResponseHeader().toString());
-
-        if (HttpHeader.GZIP.equals(
-                msg.getResponseHeader().getHeader(HttpHeader.CONTENT_ENCODING))) {
-            // Uncompress gziped content
-            try (ByteArrayInputStream bais =
-                            new ByteArrayInputStream(msg.getResponseBody().getBytes());
-                    GZIPInputStream gis = new GZIPInputStream(bais);
-                    InputStreamReader isr = new InputStreamReader(gis);
-                    BufferedReader br = new BufferedReader(isr); ) {
-                StringBuilder sb = new StringBuilder();
-                String line = null;
-                while ((line = br.readLine()) != null) {
-                    sb.append(line);
-                }
-                map.put("responseBody", sb.toString());
-            } catch (IOException e) {
-                LOGGER.error("Unable to uncompress gzip content: " + e.getMessage(), e);
-                map.put("responseBody", msg.getResponseBody().toString());
-            }
-        } else {
-            map.put("responseBody", msg.getResponseBody().toString());
-        }
+        map.put("responseBody", msg.getResponseBody().toString());
 
         List<String> tags = Collections.emptyList();
         try {
diff --git a/zap/src/test/java/org/zaproxy/zap/extension/api/ApiResponseConversionUtilsUnitTest.java b/zap/src/test/java/org/zaproxy/zap/extension/api/ApiResponseConversionUtilsUnitTest.java
index 15720ad90..d194ecfc1 100644
--- a/zap/src/test/java/org/zaproxy/zap/extension/api/ApiResponseConversionUtilsUnitTest.java
+++ b/zap/src/test/java/org/zaproxy/zap/extension/api/ApiResponseConversionUtilsUnitTest.java
@@ -24,14 +24,11 @@ import static org.hamcrest.Matchers.hasEntry;
 import static org.hamcrest.Matchers.is;
 import static org.mockito.BDDMockito.given;
 
-import java.io.ByteArrayOutputStream;
-import java.util.zip.GZIPOutputStream;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
-import org.parosproxy.paros.network.HttpHeader;
 import org.parosproxy.paros.network.HttpMessage;
 import org.parosproxy.paros.network.HttpRequestHeader;
 import org.parosproxy.paros.network.HttpResponseHeader;
@@ -112,32 +109,4 @@ class ApiResponseConversionUtilsUnitTest {
         assertThat(response.getValues(), hasEntry("timestamp", "1010101010101"));
         assertThat(response.getValues(), hasEntry("rtt", "200"));
     }
-
-    @Test
-    void compressedResponseBodyShouldBeDeflatedIntoApiResponse() throws Exception {
-        given(responseHeader.getHeader(HttpHeader.CONTENT_ENCODING)).willReturn(HttpHeader.GZIP);
-        given(responseBody.getBytes()).willReturn(gzip(new byte[] {97, 98, 99}));
-
-        ApiResponseSet<String> response = ApiResponseConversionUtils.httpMessageToSet(0, message);
-
-        assertThat(response.getValues(), hasEntry("responseBody", "abc"));
-    }
-
-    @Test
-    void brokenCompressedResponseBodyShouldBeStoredAsStringRepresentationInApiResponse() {
-        given(responseHeader.getHeader(HttpHeader.CONTENT_ENCODING)).willReturn(HttpHeader.GZIP);
-        given(responseBody.getBytes()).willReturn(new byte[] {0, 0, 0});
-
-        ApiResponseSet<String> response = ApiResponseConversionUtils.httpMessageToSet(0, message);
-
-        assertThat(response.getValues(), hasEntry("responseBody", responseBody.toString()));
-    }
-
-    private static byte[] gzip(byte[] raw) throws Exception {
-        ByteArrayOutputStream bytes = new ByteArrayOutputStream(raw.length);
-        try (GZIPOutputStream zip = new GZIPOutputStream(bytes)) {
-            zip.write(raw);
-        }
-        return bytes.toByteArray();
-    }
 }