ProxymanApp / Proxyman

Modern. Native. Delightful Web Debugging Proxy for macOS, iOS, and Android ⚑️
https://proxyman.io
5.69k stars 187 forks source link

Feature Request - Allow Map Local/Remote with Scripting #606

Open mattbenton opened 4 years ago

mattbenton commented 4 years ago

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.

NghiaTranUIT commented 4 years ago

@mattbenton Thank you for the detailed report πŸ‘

I understand your situation, I'd suggest:

mattbenton commented 4 years ago

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.

NghiaTranUIT commented 4 years ago

Thanks for the hint πŸŽ‰. I'm on it now and I will send you a hotfix today πŸ‘

NghiaTranUIT commented 4 years ago

@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;
    }
  3. It works
Screen_Shot_2020-08-31_at_10_20_03
mattbenton commented 4 years ago

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

NghiaTranUIT commented 4 years ago

Glad to hear that πŸ‘ I will roll out the release in the week πŸŽ‰

ldraminski commented 2 years ago

@NghiaTranUIT And what about remote map?

Mausved commented 11 months ago

@NghiaTranUIT yes, scripting after map remote is still actual πŸ₯²

NghiaTranUIT commented 11 months ago

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

Let me implement it and send you guys a Beta build πŸ‘

NghiaTranUIT commented 11 months ago

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

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 πŸ‘

Mausved commented 10 months ago

@NghiaTranUIT thank you so much! This is what I need πŸ˜ƒ Everything is okey

linkjane commented 10 months ago

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

NghiaTranUIT commented 10 months ago

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