coolboywcm commented on issue #9961:
URL: https://github.com/apache/apisix/issues/9961#issuecomment-1665340474

   > @coolboywcm APISIX doesn't tamper with the response and passes it as it 
is. Can you confirm if the response sent by your upstream directly to see if 
the this invalid response is coming from upstream?
   
   I'm  really sure it's the gzip response mode of the upstream service causing 
garbled logs, which I've reproduced in my development environment.
   **non-gzip** mode, the upstream service code is as follows:
   
   ```
   public void test_no_gzip(){
           HttpServletResponse response =  getResponse();
           response.setContentType("application/json;charset=UTF-8");
           JSONObject result = new JSONObject();
           result.put("key1","123234");
           try {
               ServletOutputStream servletOutputStream = 
response.getOutputStream();
               
servletOutputStream.write(result.toJSONString().getBytes("UTF-8"));
               servletOutputStream.close();
           } catch (IOException e) {
               e.printStackTrace();
           }
       }
       
   ```
   Received log content:
   
   
`{"response":{"status":200,"headers":{"access-control-allow-headers":"Content-Type,X-Requested-With,withCredentials","connection":"close","date":"Fri,
 04 Aug 2023 09:39:26 
GMT","access-control-allow-origin":"*","server":"APISIX\/3.1.0","content-type":"application\/json;charset=UTF-8","access-control-allow-methods":"GET,
 POST","content-length":"17"},"body":"{\"key1\":\"123234\"}","size":333}}
   `
   
   **gzip** mode, the upstream service code is as follows:
   
   ```
       public void test_gzip(){
           HttpServletResponse response =  getResponse();
           response.setHeader("Content-Encoding", "gzip");
           response.setContentType("application/json;charset=UTF-8");
           JSONObject result = new JSONObject();
           result.put("key1","123234");
           try {
               GZIPOutputStream gzipOutputStream = new 
GZIPOutputStream(response.getOutputStream());
               gzipOutputStream.write(result.toJSONString().getBytes("UTF-8"));
               gzipOutputStream.close();
           } catch (IOException e) {
               e.printStackTrace();
           }
       }
   ```
       
    Received log content:   
   
   ` 
{"response":{"status":200,"headers":{"connection":"close","access-control-allow-origin":"*","server":"APISIX\/3.1.0","content-type":"application\/json;charset=UTF-8","date":"Fri,
 04 Aug 2023 09:47:27 
GMT","content-encoding":"gzip","access-control-allow-headers":"Content-Type,X-Requested-With,withCredentials","access-control-allow-methods":"GET,
 
POST","content-length":"37"},"body":"\u001f�\b\u0000\u0000\u0000\u0000\u0000\u0000\u0000�V�N�4T�R242626Q�\u0005\u0000��_�\u0011\u0000\u0000\u0000","size":377}}`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to