requestly / requestly-desktop-app

Requestly Desktop App (Mac, Linux, Windows)
https://requestly.com
GNU Affero General Public License v3.0
49 stars 12 forks source link

Redirect Request and Replace String simply use 307 instead of working as a transparent proxy #91

Open 7nights opened 3 months ago

7nights commented 3 months ago

Summary

I've tried these 2 ways to try to implement something like Charles map remote which allows you to intercept requests and replace the response with another request. But I found Requestly implement these 2 features by generating a 307 http code and redirect to the new URL which doesn't work in most of my scenarios. Is this how it is designed or am I misunderstanding it?

nsrCodes commented 3 months ago

@7nights You are right, This is currently how it is designed to work.

Why we don't provide a transparent-proxy-like redirect Building a transparent proxy-like redirect is currently not on our roadmap since our earlier attempts to do so revealed that many open-ended edge cases need to be handled for this to keep our proxy predictably working. This is because its more than just serving a new response. There are too many incompatibilities between headers when request is served from an unexpected responder and especially many cases of CORS that need to be handled as well for different kinds of browsers (Safari chrome and firefox all have slightly different ways of handling this)

But, if you only intend to change the response body, you can achieve the same result by using creating a programmatic modify response rule instead of a replace/redirect rule.

In there, you can make a request to the URL (the function can be made async) where you intended the request to redirect to and serve its response. I meant something like this:

async function modifyResponse(args) {
  const {method, url, response, responseType, requestHeaders, requestData, responseJSON} = args;
  const newResponse = await fetch(<redirection-target-url>)
  return newResponse;
}

let me know if this solves your issue.