[GH-ISSUE #894] Scripting error when application uses wrong content-type #889

Open
opened 2026-03-03 19:22:44 +03:00 by kerem · 2 comments
Owner

Originally created by @TemporalAgent7 on GitHub (May 21, 2021).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/894

Originally assigned to: @NghiaTranUIT on GitHub.

Proxyman version? (Ex. Proxyman 1.4.3)

2.25.0 (22500)

macOS Version? (Ex. mac 10.14)

mac 11.3.1

Steps to reproduce

The application sends an invalid JSON object with Content-Type=application/json. I want to log this value.

function onRequest(context, url, request) {
  console.log(request);
  return request;
}

I'm getting this error:

Error: Invalid JSON Object from given body. (Content-Type=application/json)

Expected behavior

Add a way to pass invalid body data with application/json content-type (maybe a flag ignoreContentType or something of that nature).

Workarounds are also welcome (I can't fix the body, the app's server expects the invalid values).

Originally created by @TemporalAgent7 on GitHub (May 21, 2021). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/894 Originally assigned to: @NghiaTranUIT on GitHub. ### Proxyman version? (Ex. Proxyman 1.4.3) 2.25.0 (22500) ### macOS Version? (Ex. mac 10.14) mac 11.3.1 ### Steps to reproduce The application sends an invalid JSON object with Content-Type=application/json. I want to log this value. ```js function onRequest(context, url, request) { console.log(request); return request; } ``` I'm getting this error: `Error: Invalid JSON Object from given body. (Content-Type=application/json)` ### Expected behavior Add a way to pass invalid body data with application/json content-type (maybe a flag `ignoreContentType` or something of that nature). Workarounds are also welcome (I can't fix the body, the app's server expects the invalid values).
Author
Owner

@NghiaTranUIT commented on GitHub (May 21, 2021):

Hey @TemporalAgent7, since the Content-Type is invalid, so Proxyman could not know what type of the Request.Body to parse. Therefore, you get the error log.

To workaround, please look at the Request object at https://docs.proxyman.io/scripting/script#onrequest-object-format

You can access the rawBody and manually parse it to JSON object with JSON.parse()

For example:

// Raw String body
var rawBody = request.rawBody;

// pares to JSON Object
var jsonBody = JSON.parse(rawBody);

// Update data
jsonBody["id"] = 123;

// Override again
request.body = jsonBody;

// Set JSON again so Proxyman can parse it
request.headers["Content-Type"] = "application/json";

return request;
<!-- gh-comment-id:845675595 --> @NghiaTranUIT commented on GitHub (May 21, 2021): Hey @TemporalAgent7, since the Content-Type is invalid, so Proxyman could not know what type of the Request.Body to parse. Therefore, you get the error log. To workaround, please look at the Request object at https://docs.proxyman.io/scripting/script#onrequest-object-format You can access the rawBody and manually parse it to JSON object with JSON.parse() For example: ```js // Raw String body var rawBody = request.rawBody; // pares to JSON Object var jsonBody = JSON.parse(rawBody); // Update data jsonBody["id"] = 123; // Override again request.body = jsonBody; // Set JSON again so Proxyman can parse it request.headers["Content-Type"] = "application/json"; return request; ```
Author
Owner

@TemporalAgent7 commented on GitHub (May 21, 2021):

The remote server expects the data in invalid format, it will not process correctly if I send it JSON, it will also not process correctly if I send a different content-type.

It would be nice to have the option to be able to write to rawBody and configure Proxyman to ignore invalid content types.

<!-- gh-comment-id:846040241 --> @TemporalAgent7 commented on GitHub (May 21, 2021): The remote server expects the data in invalid format, it will not process correctly if I send it JSON, it will also not process correctly if I send a different content-type. It would be nice to have the option to be able to write to rawBody and configure Proxyman to ignore invalid content types.
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#889
No description provided.