[GH-ISSUE #792] Keep headers from original response in map local #786

Closed
opened 2026-03-03 19:21:53 +03:00 by kerem · 2 comments
Owner

Originally created by @lkipke on GitHub (Feb 17, 2021).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/792

Originally assigned to: @NghiaTranUIT on GitHub.

Proxyman version?

Proxyman 2.18.0

macOS Version?

mac 10.14.6

Steps to reproduce

  1. Create a "Map local" rule that maps to a JSON file.
  2. Send the request (from Chrome, for example)
  3. Observe that the response headers all get removed, and replaced with default headers:
    HTTP/1.1 200 OK
    Content-Type: application/json
    Content-Length: 11661
    X-Proxyman-Map-Local: Serve from file: /path/to/file.json
    

Expected behavior

Since my map local rule only rewrites the body, I would expect that all of the original response headers are kept on the response (except probably Content-Length). Currently, this prevents CORS-enabled requests, because the Access-Control-Allow-Origin header is removed from the response.

I think that I can work around this by using the scripting tool, but it'd be nice to have the map local tool support it as well 😄 Also, this is a great product -- love it so far!

Originally created by @lkipke on GitHub (Feb 17, 2021). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/792 Originally assigned to: @NghiaTranUIT on GitHub. ### Proxyman version? Proxyman 2.18.0 ### macOS Version? mac 10.14.6 ### Steps to reproduce 1. Create a "Map local" rule that maps to a JSON file. 2. Send the request (from Chrome, for example) 3. Observe that the response headers all get removed, and replaced with default headers: ``` HTTP/1.1 200 OK Content-Type: application/json Content-Length: 11661 X-Proxyman-Map-Local: Serve from file: /path/to/file.json ``` ### Expected behavior Since my map local rule _only_ rewrites the body, I would expect that all of the original response headers are kept on the response (except probably `Content-Length`). Currently, this prevents CORS-enabled requests, because the `Access-Control-Allow-Origin` header is removed from the response. I think that I can work around this by using the scripting tool, but it'd be nice to have the map local tool support it as well 😄 Also, this is a great product -- love it so far!
kerem closed this issue 2026-03-03 19:21:53 +03:00
Author
Owner

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

Hi. Thanks for your kind words 😄

I would expect that all of the original response headers are kept on the response (except probably Content-Length).

Unfortunately, Map Local doesn't make any real requests to your server, so Proxyman doesn't know the real Response from your server. We intentionally implement by this way because it's possible to do Mock API. For instance, you can call a fake Endpoint (e.g. www.fakedomain.com/api) and provide a response with Map Local tool.

Currently, this prevents CORS-enabled requests, because the Access-Control-Allow-Origin header is removed from the response.

There are several ways to achieve this:

1. Create Map Local rule from Right-Context Menu

  1. Make a real request that has the Access-Control-Allow-Origin header in the response
  2. Right-Click -> Tools -> Map Local
  3. From now, the Map Local Rule will contain all Response Header and the body
  4. You can directly modify the Body as you wish
Screen Shot 2021-02-18 at 15 44 40

2. Define Map Local as an entire HTTP Message (includes Headers and Body)

  1. Instead of selecting the body in the Map Local Tool, you can define a Response Header and copy the JSON to the body.
Screen_Shot_2021-02-18_at_15_45_01

3. Using Scripting

  1. Import JSON file (https://docs.proxyman.io/scripting/snippet-code#json)
  2. By-pass CORS (https://docs.proxyman.io/scripting/snippet-code#by-pass-cors)

Feel free to let me know if you struggle in some point 😄

<!-- gh-comment-id:781185567 --> @NghiaTranUIT commented on GitHub (Feb 18, 2021): Hi. Thanks for your kind words 😄 > I would expect that all of the original response headers are kept on the response (except probably Content-Length). Unfortunately, Map Local doesn't make any real requests to your server, so Proxyman doesn't know the real Response from your server. We intentionally implement by this way because it's possible to do Mock API. For instance, you can call a fake Endpoint (e.g. www.fakedomain.com/api) and provide a response with Map Local tool. > Currently, this prevents CORS-enabled requests, because the Access-Control-Allow-Origin header is removed from the response. There are several ways to achieve this: ### 1. Create Map Local rule from Right-Context Menu 1. Make a real request that has the `Access-Control-Allow-Origin` header in the response 2. Right-Click -> Tools -> Map Local 3. From now, the Map Local Rule will contain all Response Header and the body 4. You can directly modify the Body as you wish <img width="897" alt="Screen Shot 2021-02-18 at 15 44 40" src="https://user-images.githubusercontent.com/5878421/108330734-8ad95f00-7200-11eb-886c-a0eb3130689d.png"> ### 2. Define Map Local as an entire HTTP Message (includes Headers and Body) 1. Instead of selecting the body in the Map Local Tool, you can define a Response Header and copy the JSON to the body. <img width="1219" alt="Screen_Shot_2021-02-18_at_15_45_01" src="https://user-images.githubusercontent.com/5878421/108330787-9b89d500-7200-11eb-9856-b4423e301c8d.png"> ### 3. Using Scripting 1. Import JSON file (https://docs.proxyman.io/scripting/snippet-code#json) 2. By-pass CORS (https://docs.proxyman.io/scripting/snippet-code#by-pass-cors) Feel free to let me know if you struggle in some point 😄
Author
Owner

@lkipke commented on GitHub (Feb 18, 2021):

Awesome, thanks for the help! 😄

<!-- gh-comment-id:781687830 --> @lkipke commented on GitHub (Feb 18, 2021): Awesome, thanks for the help! 😄
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#786
No description provided.