Is there a tool that'll let me programatically inspect and edit http requests being emitted from my box on the fly?

I'm hoping to create the ability to access mirrors of commonly downloaded files when the primary url is down. (Bonus points to solutions that can also work on MacOS and Windows)

More concretely, here's exactly what I'm hoping to achieve:

  1. Process FOO on my machine attempts to make an https request to download a file some external service: https://someserver.com/fileA

  2. The interceptor tool notices the request being made and takes over. It proceeds to make the original request to https://someserver.com/fileA

  3. If the request is successful, the bits are returned to process FOO

  4. But if the request fails with some error code (perhaps someserver.com is down) then the interceptor tool instead makes a request to some other url (e.g. to https://backupserver.com/fileA)

  5. The interceptor tool returns the value returned by the backup url to process FOO

(This will primarily be running on an Ubuntu box, but I'll eventually need something similar for Windows and MacOS as well)

  • An http request can be intercepted by a proxy for example. For https you need to MITM yourself. Alternatively you could try to download all files from your server, from a special URL that would in turn redirect to the first available mirror. Jul 25, 2022 at 21:47
  • Proxy servers such as squid or varnish have URL mangling functions and can cache results for other systems.
    – thrig
    Jul 25, 2022 at 21:52
  • 2
    Never use just any old made up host name as an example. Only use example.com (or example.net or example.org etc, or sub-domains of these) instead. These example.* domain names are reserved for use as examples and are guaranteed never to exist. Any other domain might exist (and probably does - someserver.com and backupserver.com definitely do). See Reserved Top Level DNS Names
    – cas
    Jul 26, 2022 at 4:07
  • @cas You can also use the .example TLD, such as backupserver.example/fileA.
    – forest
    Jul 28, 2022 at 1:11

1 Answer 1


There are already some good examples in comments proxies that can do what you point out. Another example, haproxy may rewrite URL as you want with regexp, also supports LUA scripting: https://www.haproxy.com/documentation/hapee/latest/traffic-routing/rewrites/rewrite-requests/

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review Sep 6, 2022 at 12:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .