http-proxy-mitm
Use it with http-proxy to transform the response from the proxied server.
Based on node-http-proxy-json by langjt. Thank you for your work!
Motivation
There is very hard to modify non-XML response when using http-proxy. For HTML/XML document you can try Harmon.
Usually the server will compress the data, confirm your server compression format before using this repository: http-proxy-mitm
currently supports gzip、deflate and uncompressed content encoding.
If you need other compression format, try to pass in decoder and encoder as the first and the last transformer.
Installation
npm i http-proxy-mitm
Examples
Handling server with gzip compression
const zlib = ;const http = ;const httpProxy = ;const httpProxyMitm = ; // Create a proxy serverconst proxy = httpProxy; // Listen for the `proxyRes` event on `proxy`.proxy; // Create your server and then proxies the requestconst server = http; // Create your target serverconst targetServer = http;
Handling server with deflate compression
const zlib = ;const http = ;const httpProxy = ;const httpProxyMitm = ; // Create a proxy serverconst proxy = httpProxy; // Listen for the `proxyRes` event on `proxy`.proxy; // Create your server and then proxies the requestconst server = http; // Create your target serverconst targetServer = http;
Handling server without compression
const http = ;const httpProxy = ;const modifyResponse = ; // Create a proxy serverconst proxy = httpProxy; // Listen for the `proxyRes` event on `proxy`.proxy; // Create your server and then proxies the requestconst server = http; // Create your target serverconst targetServer = http;
Tests
To run the test suite, first install the dependencies, then run npm test
:
npm installnpm test