chimurai / http-proxy-middleware

:zap: The one-liner node.js http-proxy middleware for connect, express, next.js and more
MIT License
10.62k stars 825 forks source link

Intercept HTTP(s) calls and modify request "paths" on the fly #941

Closed Zabrane closed 3 months ago

Zabrane commented 10 months ago

Describe the feature you'd love to see

Hi @chimurai

I'm new to http-proxy-middleware and would like to know if it can help with my problem. Let's assume my browser tries to load this HTML page using GET:

GET https://abc.com/index.html \r\n

Is it possible to to intercept it, and instead make it look like this:

GET http://localhost:8080/https://abc.com/index.html 1.1 \r\n

Here, localhost:8080 is where my proxy is running.

Similarly, if the above HTML page contains an image (notice the relative URL of the image):

GET /images/profile.png  \r\n

that image must be intercepted and its path rewritten as:

GET http://localhost:8080/https://abc.com/images/profile.png  \r\n

The image has a relative URL which needs to be converted to an absolute one: . from: /images/profile.png . to: https://abc.com/images/profile.png . then finally rewritten as: http://localhost:8080/https://abc.com/images/profile.png

Can http-proxy-middleware be of any help here?

Thanks

Additional context (optional)

No response

chimurai commented 3 months ago

You can check the recipes: https://github.com/chimurai/http-proxy-middleware/tree/master/recipes

More specific to your use-case: https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/router.md https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/response-interceptor.md