[GH-ISSUE #604] unzip response body #599

Closed
opened 2026-03-03 19:20:13 +03:00 by kerem · 8 comments
Owner

Originally created by @trycatchx on GitHub (Aug 29, 2020).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/604

Originally assigned to: @NghiaTranUIT on GitHub.

hi:
I am the author of this issue #600
I use scripting to modify response.body.
this is my code:

function onResponse(context, url, request, response) {
  console.log('begin');
  var bodyString = JSON.stringify(response.body);
  console.log(bodyString);
  console.log(typeof(response.body));
  // Done
  return response;
}

console output:

13:02:31.661: [onResponse] with Request ID=133
begin
{}
object

I am sure the body is non-empty, but it is gzip.
Why body prints -> {} , it is null ?

Looking forward to your reply!

Originally created by @trycatchx on GitHub (Aug 29, 2020). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/604 Originally assigned to: @NghiaTranUIT on GitHub. hi: I am the author of this issue [#600 ](https://github.com/ProxymanApp/Proxyman/issues/600#issue-687944474) I use scripting to modify response.body. this is my code: ``` function onResponse(context, url, request, response) { console.log('begin'); var bodyString = JSON.stringify(response.body); console.log(bodyString); console.log(typeof(response.body)); // Done return response; } ``` console output: ---------------------------------- ``` 13:02:31.661: [onResponse] with Request ID=133 begin {} object ``` I am sure the body is non-empty, but it is gzip. Why body prints -> {} , it is null ? Looking forward to your reply!
kerem 2026-03-03 19:20:13 +03:00
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 29, 2020):

Hi @zhangchaojiong can you show me the console.log(response) 🤔

<!-- gh-comment-id:683240646 --> @NghiaTranUIT commented on GitHub (Aug 29, 2020): Hi @zhangchaojiong can you show me the `console.log(response)` 🤔
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 29, 2020):

response.body might be not a JSON object, so JSON.stringify() would return {}.

Please help me to log the response or response.body to see what it's 😄

<!-- gh-comment-id:683241025 --> @NghiaTranUIT commented on GitHub (Aug 29, 2020): `response.body` might be not a JSON object, so `JSON.stringify()` would return `{}`. Please help me to log the response or response.body to see what it's 😄
Author
Owner

@trycatchx commented on GitHub (Aug 30, 2020):

@NghiaTranUIT

Sorry to keep you waiting.

According to your suggestion, I modified my code:

function onResponse(context, url, request, response) {

  console.log('begin');
  
 var bodyString = JSON.stringify(response.body);
 console.log(bodyString);
 console.log(response.body);
 console.log(response);
   //unzip(bodyString);
 
  // Done
  return response;
}

console ouput:

----------------------------------
21:24:09.755: [onResponse] with Request ID=351
begin
{}
{}
{
	"statusCode": 200,
	"headers": {
		"U-Location": "1682005182_1683911704",
		"Date": "Sun, 30 Aug 2020 13:24:09 GMT",
		"Keep-Alive": "timeout=50",
		"Server": "nginx",
		"Connection": "keep-alive",
		"Area": "sz",
		"Content-Type": "application/octet-stream",
		"Content-Length": "1241",
		"Content-Encoding": "gzip"
	},
	"body": {},
	"httpVersion": "HTTP/1.1",
	"statusPhrase": "OK"
}
21:24:09.773 onResponse() is executed!

I am sure the http response.body is not null .
I use postMan to send http post requests, and use proxyMan to intercept them.
But the body on postman is not empty, proxyMan cannot print out body?

image

Finally, I request a non-gzip body, both postman and proxyman can run normally.
Why is the gzip body missing on proxyman?

<!-- gh-comment-id:683421795 --> @trycatchx commented on GitHub (Aug 30, 2020): @NghiaTranUIT Sorry to keep you waiting. According to your suggestion, I modified my code: ``` function onResponse(context, url, request, response) { console.log('begin'); var bodyString = JSON.stringify(response.body); console.log(bodyString); console.log(response.body); console.log(response); //unzip(bodyString); // Done return response; } ``` console ouput: ``` ---------------------------------- 21:24:09.755: [onResponse] with Request ID=351 begin {} {} { "statusCode": 200, "headers": { "U-Location": "1682005182_1683911704", "Date": "Sun, 30 Aug 2020 13:24:09 GMT", "Keep-Alive": "timeout=50", "Server": "nginx", "Connection": "keep-alive", "Area": "sz", "Content-Type": "application/octet-stream", "Content-Length": "1241", "Content-Encoding": "gzip" }, "body": {}, "httpVersion": "HTTP/1.1", "statusPhrase": "OK" } 21:24:09.773 onResponse() is executed! ``` I am sure the http response.body is not null . I use postMan to send http post requests, and use proxyMan to intercept them. But the body on postman is not empty, proxyMan cannot print out body? ![image](https://user-images.githubusercontent.com/6050250/91660470-b0669500-eb08-11ea-9e73-c55b3a1ab3af.png) Finally, I request a non-gzip body, both postman and proxyman can run normally. Why is the gzip body missing on proxyman?
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 30, 2020):

Thank for the screenshot. It looks like a bug for the binary body. I’m fixing it now 👍

<!-- gh-comment-id:683425472 --> @NghiaTranUIT commented on GitHub (Aug 30, 2020): Thank for the screenshot. It looks like a bug for the binary body. I’m fixing it now 👍
Author
Owner

@trycatchx commented on GitHub (Aug 30, 2020):

@NghiaTranUIT

Thank you for your precious time and look forward to your repair!

<!-- gh-comment-id:683426058 --> @trycatchx commented on GitHub (Aug 30, 2020): @NghiaTranUIT Thank you for your precious time and look forward to your repair!
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 31, 2020):

@zhangchaojiong Please check out this build: https://download.proxyman.io/beta/Proxyman_2.5.2_Binary_Body_Scripting.dmg

If the body is a binary data, it will convert to base64 encoded String, so please make sure using atob() to decode to Uint8Array. If you would like to ungzip, you can directly pass it as a param

const { ungzip, gzip } = require("@addons/Pako.js")

console.log(request.body) 
// Print: Base64 encoding string

var content = ungzip(request.body)
console.log(content);
// Print content string

If you would like to pass the Binary to the body, make sure you convert to base64 Encoded String too 👍

For instance,

// Import gz file
// File is converted to base64 encoded string
const file = require("@users/4BFC1646.httpbin.gz");

function onResponse(context, url, request, response) {

  response.body = file;

  // Done
  return response;
}
<!-- gh-comment-id:683603560 --> @NghiaTranUIT commented on GitHub (Aug 31, 2020): @zhangchaojiong Please check out this build: https://download.proxyman.io/beta/Proxyman_2.5.2_Binary_Body_Scripting.dmg If the body is a binary data, it will convert to base64 encoded String, so please make sure using `atob()` to decode to `Uint8Array`. If you would like to ungzip, you can directly pass it as a param ```js const { ungzip, gzip } = require("@addons/Pako.js") console.log(request.body) // Print: Base64 encoding string var content = ungzip(request.body) console.log(content); // Print content string ``` If you would like to pass the Binary to the body, make sure you convert to base64 Encoded String too 👍 For instance, ```js // Import gz file // File is converted to base64 encoded string const file = require("@users/4BFC1646.httpbin.gz"); function onResponse(context, url, request, response) { response.body = file; // Done return response; } ```
Author
Owner

@trycatchx commented on GitHub (Aug 31, 2020):

@NghiaTranUIT

https://download.proxyman.io/beta/Proxyman_2.5.2_Binary_Body_Scripting.dmg

wow, it works well !
Save me a lot of time. thx!

<!-- gh-comment-id:683610977 --> @trycatchx commented on GitHub (Aug 31, 2020): @NghiaTranUIT [https://download.proxyman.io/beta/Proxyman_2.5.2_Binary_Body_Scripting.dmg](https://download.proxyman.io/beta/Proxyman_2.5.2_Binary_Body_Scripting.dmg) wow, it works well ! Save me a lot of time. thx!
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 31, 2020):

Glad to hear that 😄 and thank you for reporting those bugs 👍

<!-- gh-comment-id:683611382 --> @NghiaTranUIT commented on GitHub (Aug 31, 2020): Glad to hear that 😄 and thank you for reporting those bugs 👍
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Proxyman#599
No description provided.