{"_id":"http-intercept","_rev":"1745893","name":"http-intercept","description":"Enhancement for Node's HTTP `IncomingMessage` & `ServerResponse` for data going from/to such streams to be intercepted - and modified... :)","dist-tags":{"latest":"0.1.1"},"maintainers":[{"name":"pvoisin","email":"pierre.voisin@gmail.com"}],"time":{"modified":"2026-11-19T14:41:38.000Z","created":"2013-07-05T04:44:40.625Z","0.1.1":"2014-11-27T05:00:47.856Z","0.1.0":"2013-07-05T04:44:40.625Z"},"users":{},"author":{"name":"Pierre Voisin","email":"pierre.voisin@gmail.com"},"repository":{"type":"git","url":"https://github.com/pvoisin/node-http-intercept"},"versions":{"0.1.1":{"name":"http-intercept","version":"0.1.1","description":"Enhancement for Node's HTTP `IncomingMessage` & `ServerResponse` for data going from/to such streams to be intercepted - and modified... :)","author":{"name":"Pierre Voisin","email":"pierre.voisin@gmail.com"},"main":"intercept.js","scripts":{"test":"echo \"Please contribute!\" && exit 1"},"repository":{"type":"git","url":"https://github.com/pvoisin/node-http-intercept"},"keywords":["HTTP","intercept","proxy","stream","transform"],"dependencies":{"lodash":"~1.3.1"},"license":"MIT","bugs":{"url":"https://github.com/pvoisin/node-http-intercept/issues"},"_id":"http-intercept@0.1.1","dist":{"shasum":"4276216cdf1094f143d33350e925c8fb7f905c2a","tarball":"http://registry-npm.ywwl.com/http-intercept/download/http-intercept-0.1.1.tgz","integrity":"sha512-oBMQe8HjUz2myciNGnwhmDWB6DdAp0QB8FBoMZa/Ks7oD/qESt7t+GdRX3HrdfNXpJDvsFsDeyvkDJq2hsD84A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFEWdWmaJkTtDvjd9AGyQnFdMjc4niR7VgJ3dK4/W7v2AiEA/bDpi/vLDyNOSHcxG/mwd5lvtyvzrpsCeCnnKIvL1Qw="}],"size":3714,"noattachment":false,"key":"/http-intercept/-/http-intercept-0.1.1.tgz"},"_from":".","_npmVersion":"1.3.10","_npmUser":{"name":"pvoisin","email":"pierre.voisin@gmail.com"},"maintainers":[{"name":"pvoisin","email":"pierre.voisin@gmail.com"}],"publish_time":1417064447856,"_cnpm_publish_time":1417064447856},"0.1.0":{"name":"http-intercept","version":"0.1.0","description":"Enhancement for Node's HTTP IncomingMessage & ServerResponse to let the data going from/to those streams to be intercepted - and modified... :)","main":"intercept.js","scripts":{"test":"echo \"Sorry, I was lazy... But you're not, are you?\" && exit 1"},"repository":{"type":"git","url":"https://github.com/pvoisin/node-http-intercept"},"keywords":["HTTP","intercept","proxy","stream","transform"],"author":{"name":"Pierre Voisin"},"license":"MIT","dependencies":{"lodash":"~1.3.1"},"_id":"http-intercept@0.1.0","dist":{"shasum":"b2c5fbcb5a3c0e6134c939abd332bcced887fb47","tarball":"http://registry-npm.ywwl.com/http-intercept/download/http-intercept-0.1.0.tgz","integrity":"sha512-XvtqFNFc9fqUwF9lb/KNmYtZwnbvm4ydE1x7LGS12mIpa1UgQh4MIKrm4ab0/KCxW7LDAjOrNuTbZ2/kKv9Y+w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDb7LUmG/E2UI3kavdSURlO1OWNOELhUOypzn97rplqYAiBp4j70qg5GCKswgoAh//p1PLlfLCJcTy7KOiDJsu122g=="}],"size":2283,"noattachment":false,"key":"/http-intercept/-/http-intercept-0.1.0.tgz"},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"pvoisin","email":"pierre.voisin@gmail.com"},"maintainers":[{"name":"pvoisin","email":"pierre.voisin@gmail.com"}],"publish_time":1372999480625,"_cnpm_publish_time":1372999480625}},"readme":"# Usage\n\nApproach is pretty simple: just call the `intercept` method on either request or response and register for the \"`interception`\" event (or just pass your callback when calling `intercept`).\nWhen it is triggered you'll get the intercepted data. At that point you could do whatever you want with it, then normal flow of things will resume...\n\n\n## Modifying Request Data\nLet's say you want to change incoming data:\n\n```\nvar HTTP = require(\"http\");\nvar Query = require(\"querystring\");\nvar read = require(\"concat-stream\");\n\nvar server = HTTP.createServer(function(request, response) {\n//*\n\trequest.intercept(function(context) {\n\t\tcontext.buffer = \"user=Jack\";\n\t});\n//*/\n\n\trequest.pipe(read(function(data) {\n\t\tvar query = Query.parse(String(data) || \"\");\n\t\tresponse.end(\"Hello, \" + query.user + \"!\");\n\t}));\n}).listen(80);\n```\n<u>Note</u>: post something like \"user=Barnabé\" and you'll see that it is turned into \"Jack\" in the greeting message.\n\n\n## Modifying Response Data\n\n```\nvar HTTP = require(\"http\");\nvar Query = require(\"querystring\");\nvar read = require(\"concat-stream\");\n\nvar server = HTTP.createServer(function(request, response) {\n\tvar user;\n//*\n\trequest.intercept(function(context) {\n\t\tuser = Query.parse(String(context.buffer) || \"\").user;\n\t\tcontext.buffer = \"user=Jack\";\n\t});\n//*/\n\n//*\n\tresponse.intercept(function(context) {\n\t\tcontext.buffer = \"Well... I guess you're not \" + query.user + \", but \" + user + \", right?\";\n\t});\n//*/\n\n\tvar query;\n\n\trequest.pipe(read(function(data) {\n\t\tquery = Query.parse(String(data) || \"\");\n\t\tresponse.end(\"Hello, \" + query.user + \"!\");\n\t}));\n}).listen(80);\n```","_attachments":{},"bugs":{"url":"https://github.com/pvoisin/node-http-intercept/issues"},"license":"MIT"}