If you want to intercept a Node.js application specifically, there is no global configuration option, but you can use the global-agent npm module with a GLOBAL_AGENT_HTTP_PROXY environment variable to do this like so:Įxport NODE_EXTRA_CA_CERTS =/path/to/cert.pem # Trust the cert export GLOBAL_AGENT_HTTP_PROXY =: $YOUR_PROXY_PORT # Use the proxy # Start your target app, fully intercepted: node -r 'global-agent/bootstrap' your-target-app.js Alternatively, in many cases you can change your system-wide proxy settings to use this proxy, but be aware that this will intercept all traffic on your machine, not just the target application. You can often get away with just setting HTTP_PROXY and HTTPS_PROXY environment variables to :$YOUR_PROXY_PORT, as that's a common convention, but that won't work everywhere. Configure the client to trust your HTTPS CA certificateĬonfiguring your client to use your proxyĬonfiguring the proxy settings will depend on the specific HTTP client you're using, but is normally fairly simple and well documented.Configure the client to use your Mockttp proxy as its HTTP(S) proxy.So far we've created a proxy that can automatically rewrite specific traffic from a Chromium-based browser. Check the docs for a full list of the options and return values available. You can similarly use beforeRequest to change the content of outgoing requests. The second rule will forward requests upstream, get a response, and then run the custom logic before returning the appended response back to the client: The first rule will handle all requests by itself. Getting started with Mockttp is easy: install it, define a server, and start it. On the other hand, if you do want to build scripts and automations that capture & rewrite HTTPS, or if you've used HTTP Toolkit and now you want to create complex custom behaviour on top of its built-in rules, then Mockttp is perfect, and you're in the right place. It can act as an HTTP(S) server or proxy, to intercept and mock traffic, transform responses, inject errors, or fire events for all the traffic it receives.įirst though, if you want to inspect & edit HTTP manually with a full UI and tools on top, it's better to download HTTP Toolkit for free right now instead, and start there! Mockttp is the open-source HTTP library that powers all the internals of HTTP Toolkit, built in TypeScript. Using easily available JS libraries and scripts, you can start injecting code into HTTP interactions in no time at all. It turns out setting this up is super quick & easy to do.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |