[GH-ISSUE #780] No way to filter on request body #774

Open
opened 2026-03-03 19:21:47 +03:00 by kerem · 3 comments
Owner

Originally created by @rsaunders100 on GitHub (Feb 5, 2021).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/780

Originally assigned to: @NghiaTranUIT on GitHub.

Proxyman version? (Ex. Proxyman 1.4.3)

Version 2.16.1 (21610)

We have a universal endpoint, the request body changes not the URL so there is no way to filter on a particular request for rewrite or a breakpoint.

Screenshot 2021-02-05 at 21 01 26

Originally created by @rsaunders100 on GitHub (Feb 5, 2021). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/780 Originally assigned to: @NghiaTranUIT on GitHub. ### Proxyman version? (Ex. Proxyman 1.4.3) Version 2.16.1 (21610) We have a universal endpoint, the request body changes not the URL so there is no way to filter on a particular request for rewrite or a breakpoint. ![Screenshot 2021-02-05 at 21 01 26](https://user-images.githubusercontent.com/555546/107089158-0f39e400-67f6-11eb-9997-ef00f0446d63.png)
Author
Owner

@NghiaTranUIT commented on GitHub (Feb 6, 2021):

Hi @rsaunders100, we'd not introduce the "Request Body Matching" because it could make the UI more complicated.

To resolve it, I'd highly suggest using ReWrite. Here is an example to solve your cases:

  1. Create a scripting rule (URL = https://example.com)
  2. Use the following script to match the Request and then mapping the Response (Please read the comment)
// Import file from More Button -> Import JSON or Other files 
const file = require("@users/B02D96D5.default_message_32E64A5B.json");

function onRequest(context, url, request) {

  // 1. Extract the name from Request Body
  // request.body is a JSON, so you can get whatever you want
  var queryName = request.body["name"]

  // 2. Save to sharedState
  sharedState.queryName = queryName

  // Done
  return request;
}

function onResponse(context, url, request, response) {
  
  // 3. Check if it's the request we need to map
  if (sharedState.queryName == "getUser") {
    
    // 4. Import the local file by Action Button -> Import
    // Get the local JSON file and set it as a body (like Map Local)
    response.headers["Content-Type"] = "application/json";
    response.body = file;
    
    // Or change header, status code, body like Breakpoint Tool
    // Example: https://docs.proxyman.io/scripting/snippet-code#2-common-on-request-and-response
  }

  // Done
  return response;
}
  1. Profit 😄
Screen Shot 2021-02-06 at 09 17 33

Notes

<!-- gh-comment-id:774381312 --> @NghiaTranUIT commented on GitHub (Feb 6, 2021): Hi @rsaunders100, we'd not introduce the "Request Body Matching" because it could make the UI more complicated. To resolve it, I'd highly suggest using ReWrite. Here is an example to solve your cases: 1. Create a scripting rule (URL = https://example.com) 2. Use the following script to match the Request and then mapping the Response (Please read the comment) ```js // Import file from More Button -> Import JSON or Other files const file = require("@users/B02D96D5.default_message_32E64A5B.json"); function onRequest(context, url, request) { // 1. Extract the name from Request Body // request.body is a JSON, so you can get whatever you want var queryName = request.body["name"] // 2. Save to sharedState sharedState.queryName = queryName // Done return request; } function onResponse(context, url, request, response) { // 3. Check if it's the request we need to map if (sharedState.queryName == "getUser") { // 4. Import the local file by Action Button -> Import // Get the local JSON file and set it as a body (like Map Local) response.headers["Content-Type"] = "application/json"; response.body = file; // Or change header, status code, body like Breakpoint Tool // Example: https://docs.proxyman.io/scripting/snippet-code#2-common-on-request-and-response } // Done return response; } ``` 3. Profit 😄 <img width="1354" alt="Screen Shot 2021-02-06 at 09 17 33" src="https://user-images.githubusercontent.com/5878421/107106035-2a3f3f00-685c-11eb-96d4-4b884f97197c.png"> ### Notes - By using the Scripting tool, You can write JS code to mimic the behavior of Map Local and Breakpoint programmatically - This approach is using for graphQL (Blog: https://proxyman.io/blog/2021/01/How-To-Map_Response_For_GraphQL_Requests.html)
Author
Owner

@rsaunders100 commented on GitHub (Feb 8, 2021):

Thanks! Very helpful.

Is the sharedState variable specific to the request response pair? Or is it global for all requests?

<!-- gh-comment-id:775145538 --> @rsaunders100 commented on GitHub (Feb 8, 2021): Thanks! Very helpful. Is the `sharedState` variable specific to the request response pair? Or is it global for all requests?
Author
Owner

@NghiaTranUIT commented on GitHub (Feb 8, 2021):

Yes, it's only available in this request-response pair (not global variable for all requests). You can read more at https://docs.proxyman.io/scripting/environment-variables @rsaunders100

<!-- gh-comment-id:775146167 --> @NghiaTranUIT commented on GitHub (Feb 8, 2021): Yes, it's only available in this request-response pair (not global variable for all requests). You can read more at https://docs.proxyman.io/scripting/environment-variables @rsaunders100
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#774
No description provided.