{"id":17402327,"url":"https://github.com/qfox/http-proxy-mitm","last_synced_at":"2025-10-16T08:17:57.240Z","repository":{"id":148551075,"uuid":"80240597","full_name":"qfox/http-proxy-mitm","owner":"qfox","description":"↔️️ Best use with node-http-proxy. Allows to modify response on condition.","archived":false,"fork":false,"pushed_at":"2017-01-28T02:04:13.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T22:34:26.436Z","etag":null,"topics":["http-proxy","middleware","node-http-proxy","response","transformer"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qfox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-27T19:49:46.000Z","updated_at":"2017-01-28T10:43:03.000Z","dependencies_parsed_at":"2023-05-20T12:00:50.821Z","dependency_job_id":null,"html_url":"https://github.com/qfox/http-proxy-mitm","commit_stats":{"total_commits":15,"total_committers":4,"mean_commits":3.75,"dds":0.6666666666666667,"last_synced_commit":"427fec864748ae68e9ef87fa6cfd0caa5b094347"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/qfox/http-proxy-mitm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qfox%2Fhttp-proxy-mitm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qfox%2Fhttp-proxy-mitm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qfox%2Fhttp-proxy-mitm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qfox%2Fhttp-proxy-mitm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qfox","download_url":"https://codeload.github.com/qfox/http-proxy-mitm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qfox%2Fhttp-proxy-mitm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279169134,"owners_count":26118396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-16T02:00:06.019Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http-proxy","middleware","node-http-proxy","response","transformer"],"created_at":"2024-10-16T17:26:11.646Z","updated_at":"2025-10-16T08:17:57.225Z","avatar_url":"https://github.com/qfox.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# http-proxy-mitm [![Build Status](https://travis-ci.org/zxqfox/http-proxy-mitm.svg?branch=master)](https://travis-ci.org/zxqfox/http-proxy-mitm)\n\nUse it with [http-proxy][] to transform the response from the proxied server.\n\n\u003e Based on [node-http-proxy-json][] by [langjt][]. Thank you for your work!\n\n## Motivation\n\nThere is very hard to modify non-XML response when using [http-proxy][]. For HTML/XML document you can try [Harmon](https://github.com/No9/harmon).\n\nUsually 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.\n\nIf you need other compression format, try to pass in decoder and encoder as the first and the last transformer.\n\n## Installation\n\n```sh\nnpm i http-proxy-mitm\n```\n\n## Examples\n\n### Handling server with gzip compression\n\n```js\nconst zlib = require('zlib');\nconst http = require('http');\nconst httpProxy = require('http-proxy');\nconst httpProxyMitm = require('http-proxy-mitm');\n\n// Create a proxy server\nconst proxy = httpProxy.createProxyServer({\n    target: 'http://localhost:5001'\n});\n\n// Listen for the `proxyRes` event on `proxy`.\nproxy.on('proxyRes', httpProxyMitm([\n    {\n        condition: function(res, req) { return req.url === '/1'; },\n        bodyTransform: function (body) {\n            body = JSON.parse(body);\n            if (body) {\n                body.age = 2;\n                body.version = undefined;\n            }\n            return JSON.stringify(body);\n        }\n    },\n    {\n        condition: function(res, req) { return req.url === '/2'; },\n        transform: through2(function (chunk, enc, cb) {\n            cb(null, new Buffer(chunk.toString().replace(',\"age\":1', ',\"age\":2').replace(',\"version\":\"1.0.0\"', '')));\n        })\n    }\n]));\n\n// Create your server and then proxies the request\nconst server = http.createServer(function (req, res) {\n    proxy.web(req, res);\n}).listen(5000);\n\n// Create your target server\nconst targetServer = http.createServer(function (req, res) {\n    // Create gzipped content\n    const gzip = zlib.Gzip();\n    gzip.pipe(res);\n\n    res.writeHead(200, {'Content-Type': 'application/json', 'Content-Encoding': 'gzip'});\n    gzip.write(JSON.stringify({name: 'node-http-proxy-mitm', age: 1, version: '1.0.0'}));\n    gzip.end();\n}).listen(5001);\n```\n\n### Handling server with deflate compression\n\n```js\nconst zlib = require('zlib');\nconst http = require('http');\nconst httpProxy = require('http-proxy');\nconst httpProxyMitm = require('http-proxy-mitm');\n\n// Create a proxy server\nconst proxy = httpProxy.createProxyServer({\n    target: 'http://localhost:5001'\n});\n\n// Listen for the `proxyRes` event on `proxy`.\nproxy.on('proxyRes', httpProxyMitm([{\n    transform: through2(function (chunk, enc, cb) {\n        cb(null, new Buffer(chunk.toString().replace(',\"age\":1', ',\"age\":2').replace(',\"version\":\"1.0.0\"', '')));\n    })\n}]));\n\n// Create your server and then proxies the request\nconst server = http.createServer(function (req, res) {\n    proxy.web(req, res);\n}).listen(5000);\n\n// Create your target server\nconst targetServer = http.createServer(function (req, res) {\n    // Create deflated content\n    const deflate = zlib.Deflate();\n    deflate.pipe(res);\n\n    res.writeHead(200, {'Content-Type': 'application/json', 'Content-Encoding': 'deflate'});\n    deflate.write(JSON.stringify({name: 'node-http-proxy-mitm', age: 1, version: '1.0.0'}));\n    deflate.end();\n}).listen(5001);\n```\n\n### Handling server without compression\n\n```js\nconst http = require('http');\nconst httpProxy = require('http-proxy');\nconst modifyResponse = require('../');\n\n// Create a proxy server\nconst proxy = httpProxy.createProxyServer({\n    target: 'http://localhost:5001'\n});\n\n// Listen for the `proxyRes` event on `proxy`.\nproxy.on('proxyRes', httpProxyMitm([{\n    transform: through2(function (chunk, enc, cb) {\n        cb(null, new Buffer(chunk.toString().replace(',\"age\":1', ',\"age\":2').replace(',\"version\":\"1.0.0\"', '')));\n    })\n}]));\n\n// Create your server and then proxies the request\nconst server = http.createServer(function (req, res) {\n    proxy.web(req, res);\n}).listen(5000);\n\n// Create your target server\nconst targetServer = http.createServer(function (req, res) {\n    res.writeHead(200, {'Content-Type': 'application/json', 'Content-Encoding': 'deflate'});\n    res.write(JSON.stringify({name: 'node-http-proxy-mitm', age: 1, version: '1.0.0'}));\n    res.end();\n}).listen(5001);\n```\n\n## Tests\n\nTo run the test suite, first install the dependencies, then run `npm test`:\n\n```sh\nnpm install\nnpm test\n```\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT)\n\n\n[http-proxy]: https://github.com/nodejitsu/node-http-proxy\n[node-http-proxy-json]: https://github.com/langjt/node-http-proxy-json\n[langjt]: https://github.com/langjt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqfox%2Fhttp-proxy-mitm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqfox%2Fhttp-proxy-mitm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqfox%2Fhttp-proxy-mitm/lists"}