[GH-ISSUE #606] Feature Request - Allow Map Local/Remote with Scripting #604

Open
opened 2026-03-03 19:20:15 +03:00 by kerem · 13 comments
Owner

Originally created by @mattbenton on GitHub (Aug 30, 2020).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/606

Originally assigned to: @NghiaTranUIT on GitHub.

Proxyman version?

2.5.2 (20520)

macOS Version?

10.15.6 (19G2021)

Feature Request

Allow "Map Local" and "Map Remote" features to work with "Scripting" for the same request.

Current Behavior

When Scripting is enabled for the same request as Map Local, Map Local is ignored.

Expected Behavior

It would be great if Map Local can run first to replace the body of the response.

After this, additional Scripting can be used to further modify the response body or headers.

Example use case

I am trying to use Map Local to map an entire directory to test changes before deploying changes to an app online. Map Local causes all CORS headers to be lost. (Note, the same thing happens in Charles Proxy).

I was hoping I would be able to use the Scripting feature to modify the headers in the response to allow CORS again after the mapping has run.

In Charles Proxy I was able to use the Map Local and "Rewrite" features at the same time to achieve this, though it was quite convoluted to achieve. So far it is impossible to achieve in Proxyman.


By the way, thank you for your work on this awesome tool. I first noticed this tool a month ago and I purchased a license as soon as you released the scripting feature. I believe allowing scripting to work with mapping would make tool even more attractive.

Originally created by @mattbenton on GitHub (Aug 30, 2020). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/606 Originally assigned to: @NghiaTranUIT on GitHub. ### Proxyman version? 2.5.2 (20520) ### macOS Version? 10.15.6 (19G2021) ### Feature Request Allow "Map Local" and "Map Remote" features to work with "Scripting" for the same request. ### Current Behavior When Scripting is enabled for the same request as Map Local, Map Local is ignored. ### Expected Behavior It would be great if Map Local can run first to replace the body of the response. After this, additional Scripting can be used to further modify the response body or headers. ### Example use case I am trying to use Map Local to map an entire directory to test changes before deploying changes to an app online. Map Local causes all CORS headers to be lost. (Note, the same thing happens in Charles Proxy). I was hoping I would be able to use the Scripting feature to modify the headers in the response to allow CORS again after the mapping has run. In Charles Proxy I was able to use the Map Local and "Rewrite" features at the same time to achieve this, though it was quite convoluted to achieve. So far it is impossible to achieve in Proxyman. --- By the way, thank you for your work on this awesome tool. I first noticed this tool a month ago and I purchased a license as soon as you released the scripting feature. I believe allowing scripting to work with mapping would make tool even more attractive.
Author
Owner

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

@mattbenton Thank you for the detailed report 👍

I understand your situation, I'd suggest:

  • Allow Script after Map Local (File or Directory) likes Charles => This change is trivial and I'm working on it now 🙌
  • In the near future, I will add an option to Map Directory that allows all domains in the CORS header. Thus, it's convenience for you and other users. They don't need to set up a Script to bypass the CORS. All are handle automatically. => To achieve it, Can you share with me what CROS Header you often use?
<!-- gh-comment-id:683509849 --> @NghiaTranUIT commented on GitHub (Aug 31, 2020): @mattbenton Thank you for the detailed report 👍 I understand your situation, I'd suggest: - Allow Script after Map Local (File or Directory) likes Charles => This change is trivial and I'm working on it now 🙌 - In the near future, I will add an option to Map Directory that allows all domains in the CORS header. Thus, it's convenience for you and other users. They don't need to set up a Script to bypass the CORS. All are handle automatically. => To achieve it, Can you share with me what CROS Header you often use?
Author
Owner

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

Thanks for the quick response!

For simple CORS use cases, adding a response header of Access-Control-Allow-Origin: * may be sufficient. That is something you could consider for the convenience option you proposed.

However, in my specific scenario I will still need to use scripting because our app sends credentials with CORS requests. When credentials (cookies) are sent, the browser does not allow wildcard * origins to be used and you must reply with a specific origin value, e.g. https://domain1.com. For my use case, I am mapping content that is used across multiple domains so I need to use scripting to dynamically set the Access-Control-Allow-Origin response header to the origin/domain making the request.

<!-- gh-comment-id:683512185 --> @mattbenton commented on GitHub (Aug 31, 2020): Thanks for the quick response! For simple CORS use cases, adding a response header of `Access-Control-Allow-Origin: *` may be sufficient. That is something you could consider for the convenience option you proposed. However, in my specific scenario I will still need to use scripting because our app sends credentials with CORS requests. When credentials (cookies) are sent, the browser does not allow wildcard `*` origins to be used and you must reply with a specific origin value, e.g. `https://domain1.com`. For my use case, I am mapping content that is used across multiple domains so I need to use scripting to dynamically set the `Access-Control-Allow-Origin` response header to the origin/domain making the request.
Author
Owner

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

Thanks for the hint 🎉. I'm on it now and I will send you a hotfix today 👍

<!-- gh-comment-id:683513234 --> @NghiaTranUIT commented on GitHub (Aug 31, 2020): Thanks for the hint 🎉. I'm on it now and I will send you a hotfix today 👍
Author
Owner

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

@mattbenton Please check out this build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.5.2_Fix_JWT_Addon.Fix+MIME.Support_MapLocal_Scripting.dmg

This build will run the Script Tool after Map Local as you expected 👍

How to setup

  1. Setup Map Local (File or Directory) and make sure it works first
  2. Setup Scripting (Right-click on the flow -> It will create automatically) and add some HTTP Headers on the Response
function onResponse(context, url, request, response) {
  // console.log(response);

  // Update or Add a new header
  response.headers["Access-Control-Allow-Origin"] = "*";

  // Done
  return response;
}
  1. It works
Screen_Shot_2020-08-31_at_10_20_03
<!-- gh-comment-id:683534529 --> @NghiaTranUIT commented on GitHub (Aug 31, 2020): @mattbenton Please check out this build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.5.2_Fix_JWT_Addon.Fix+MIME.Support_MapLocal_Scripting.dmg This build will run the Script Tool after Map Local as you expected 👍 ### How to setup 1. Setup Map Local (File or Directory) and make sure it works first 2. Setup Scripting (Right-click on the flow -> It will create automatically) and add some HTTP Headers on the Response ```js function onResponse(context, url, request, response) { // console.log(response); // Update or Add a new header response.headers["Access-Control-Allow-Origin"] = "*"; // Done return response; } ``` 3. It works <img width="694" alt="Screen_Shot_2020-08-31_at_10_20_03" src="https://user-images.githubusercontent.com/5878421/91681077-7ed8e280-eb77-11ea-8dde-b6f6f0c5f488.png">
Author
Owner

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

@NghiaTranUIT This is great! Works exactly as I'd hoped.

I also like the X-Proxyman-* headers. It makes configurations easier to debug.

Thanks for the quick turnaround 😄

I'll be suggesting this tool to my colleagues.

<!-- gh-comment-id:683548162 --> @mattbenton commented on GitHub (Aug 31, 2020): @NghiaTranUIT This is great! Works exactly as I'd hoped. I also like the `X-Proxyman-*` headers. It makes configurations easier to debug. Thanks for the quick turnaround 😄 I'll be suggesting this tool to my colleagues.
Author
Owner

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

Glad to hear that 👍 I will roll out the release in the week 🎉

<!-- gh-comment-id:683554309 --> @NghiaTranUIT commented on GitHub (Aug 31, 2020): Glad to hear that 👍 I will roll out the release in the week 🎉
Author
Owner

@ldraminski commented on GitHub (May 13, 2022):

@NghiaTranUIT And what about remote map?

<!-- gh-comment-id:1125678934 --> @ldraminski commented on GitHub (May 13, 2022): @NghiaTranUIT And what about remote map?
Author
Owner

@Mausved commented on GitHub (Dec 21, 2023):

@NghiaTranUIT yes, scripting after map remote is still actual 🥲

<!-- gh-comment-id:1866164818 --> @Mausved commented on GitHub (Dec 21, 2023): @NghiaTranUIT yes, scripting after map remote is still actual 🥲
Author
Owner

@NghiaTranUIT commented on GitHub (Dec 21, 2023):

@ldraminski @mattbenton looks like I should support: Map Remote -> Scripting

Let me implement it and send you guys a Beta build 👍

<!-- gh-comment-id:1866169051 --> @NghiaTranUIT commented on GitHub (Dec 21, 2023): @ldraminski @mattbenton looks like I should support: Map Remote -> Scripting Let me implement it and send you guys a Beta build 👍
Author
Owner

@NghiaTranUIT commented on GitHub (Dec 23, 2023):

@mattbenton @ldraminski can you try this Beta build: https://download.proxyman.io/beta/Proxyman_4.15.0_Map_Remote_Then_Scripting.dmg

  • A request can be mapped to Map Remote, then using the Scripting.

Here is how to setup:

  1. Make a Request First (e.g http://localhost:3000)
  2. Right Click -> Tools -> Map Remote -> Setup new rule to production (e.g https://httpbin.proxyman.app:443)
  3. Make a request again to verify the Map Remote work
  4. Right Click on the new request -> Tools -> Scripting
  5. Write a JS Script to modify the Request/Response as usual
  6. Make a request again: Confirm that a request will be modified by the Map REmote first -> Then modified by the Scripting

Let me know if you have find some bugs/issued 👍

<!-- gh-comment-id:1868297001 --> @NghiaTranUIT commented on GitHub (Dec 23, 2023): @mattbenton @ldraminski can you try this Beta build: https://download.proxyman.io/beta/Proxyman_4.15.0_Map_Remote_Then_Scripting.dmg - ✅ A request can be mapped to Map Remote, then using the Scripting. Here is how to setup: 1. Make a Request First (e.g http://localhost:3000) 2. Right Click -> Tools -> Map Remote -> Setup new rule to production (e.g https://httpbin.proxyman.app:443) 3. Make a request again to verify the Map Remote work 4. Right Click on the new request -> Tools -> Scripting 5. Write a JS Script to modify the Request/Response as usual 6. Make a request again: Confirm that a request will be modified by the Map REmote first -> Then modified by the Scripting ✅ --------- Let me know if you have find some bugs/issued 👍
Author
Owner

@Mausved commented on GitHub (Dec 26, 2023):

@NghiaTranUIT thank you so much! This is what I need 😃 Everything is okey

<!-- gh-comment-id:1869435580 --> @Mausved commented on GitHub (Dec 26, 2023): @NghiaTranUIT thank you so much! This is what I need 😃 Everything is okey
Author
Owner

@linkjane commented on GitHub (Jan 11, 2024):

@NghiaTranUIT Hi, does the latest Proxyman, which is 4.16.0 also have this function (using map remote with scripting simultaneously)?

<!-- gh-comment-id:1886256674 --> @linkjane commented on GitHub (Jan 11, 2024): @NghiaTranUIT Hi, does the latest Proxyman, which is 4.16.0 also have this function (using map remote with scripting simultaneously)?
Author
Owner

@NghiaTranUIT commented on GitHub (Jan 11, 2024):

@linkjane yes, it's included in the latest build v4.16.0

<!-- gh-comment-id:1886358736 --> @NghiaTranUIT commented on GitHub (Jan 11, 2024): @linkjane yes, it's included in the latest build v4.16.0
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#604
No description provided.