Proxyman icon indicating copy to clipboard operation
Proxyman copied to clipboard

Feature Request - Allow Map Local/Remote with Scripting

Open mattbenton opened this issue 4 years ago • 13 comments

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.

mattbenton avatar Aug 30 '20 23:08 mattbenton

@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?

NghiaTranUIT avatar Aug 31 '20 01:08 NghiaTranUIT

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.

mattbenton avatar Aug 31 '20 02:08 mattbenton

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

NghiaTranUIT avatar Aug 31 '20 02:08 NghiaTranUIT

@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

NghiaTranUIT avatar Aug 31 '20 03:08 NghiaTranUIT

@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.

mattbenton avatar Aug 31 '20 04:08 mattbenton

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

NghiaTranUIT avatar Aug 31 '20 05:08 NghiaTranUIT

@NghiaTranUIT And what about remote map?

ldraminski avatar May 13 '22 05:05 ldraminski

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

Mausved avatar Dec 21 '23 12:12 Mausved

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

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

NghiaTranUIT avatar Dec 21 '23 12:12 NghiaTranUIT

@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 👍

NghiaTranUIT avatar Dec 23 '23 13:12 NghiaTranUIT

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

Mausved avatar Dec 26 '23 10:12 Mausved

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

linkjane avatar Jan 11 '24 05:01 linkjane

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

NghiaTranUIT avatar Jan 11 '24 06:01 NghiaTranUIT