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(); 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": { 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