From bc56c34430f48798e878d4490038edd67e795e1d Mon Sep 17 00:00:00 2001 From: Jarrett Cruger Date: Thu, 23 Jul 2015 20:49:05 -0400 Subject: [PATCH 1/2] [dist] add isstream as a module --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index e7633d6f5..da992cfd3 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "main": "index.js", "dependencies": { "eventemitter3": "1.x.x", + "isstream": "~0.1.2", "requires-port": "0.x.x" }, "devDependencies": { From 87375a856a7cd11a06a242cbe3da45406be1f11c Mon Sep 17 00:00:00 2001 From: Jarrett Cruger Date: Thu, 23 Jul 2015 20:49:48 -0400 Subject: [PATCH 2/2] [api] ensure before/after options are proper streams for doing arbitrary transformation on requests --- lib/http-proxy/passes/web-incoming.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/http-proxy/passes/web-incoming.js b/lib/http-proxy/passes/web-incoming.js index 4070eb316..2f6194fb5 100644 --- a/lib/http-proxy/passes/web-incoming.js +++ b/lib/http-proxy/passes/web-incoming.js @@ -2,6 +2,8 @@ var http = require('http'), https = require('https'), web_o = require('./web-outgoing'), common = require('../common'), + PassThrough = require('stream').PassThrough, + isDuplex = require('isstream').isDuplex, passes = exports; web_o = Object.keys(web_o).map(function(pass) { @@ -93,6 +95,15 @@ web_o = Object.keys(web_o).map(function(pass) { function stream(req, res, options, _, server, clb) { + // + // Enable arbitary transform/duplex streams to be used on the byte streams + // + var before = isDuplex(options.before) ? options.before : new PassThrough(); + var after = isDuplex(options.after) ? options.after : new PassThrough(); + + before.on('error', proxyError); + after.on('error', proxyError); + // And we begin! server.emit('start', req, res, options.target) if(options.forward) { @@ -100,7 +111,7 @@ web_o = Object.keys(web_o).map(function(pass) { var forwardReq = (options.forward.protocol === 'https:' ? https : http).request( common.setupOutgoing(options.ssl || {}, options, req, 'forward') ); - (options.buffer || req).pipe(forwardReq); + (options.buffer || req).pipe(before).pipe(forwardReq); if(!options.target) { return res.end(); } } @@ -141,7 +152,7 @@ web_o = Object.keys(web_o).map(function(pass) { } } - (options.buffer || req).pipe(proxyReq); + (options.buffer || req).pipe(before).pipe(proxyReq); proxyReq.on('response', function(proxyRes) { if(server) { server.emit('proxyRes', proxyRes, req, res); } @@ -154,7 +165,7 @@ web_o = Object.keys(web_o).map(function(pass) { server.emit('end', req, res, proxyRes); }); - proxyRes.pipe(res); + proxyRes.pipe(after).pipe(res); }); //proxyReq.end(); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy