mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[fix] headers, fixes #467
This commit is contained in:
parent
adc5be020c
commit
60de543d04
@ -34,7 +34,7 @@ function createRightProxy(type) {
|
||||
var self = this,
|
||||
args = [].slice.call(arguments),
|
||||
cntr = args.length - 1,
|
||||
ev = 'caronte:' + type + ':',
|
||||
ev = 'caronte:' + type + ':incoming:',
|
||||
head;
|
||||
|
||||
if(
|
||||
@ -53,7 +53,7 @@ function createRightProxy(type) {
|
||||
|
||||
|
||||
passes.some(function(pass) {
|
||||
var evnt = ev + pass.name.toLowerCase();
|
||||
var evnt = ev + pass.name.toLowerCase() + ':';
|
||||
|
||||
options.ee.emit(evnt + 'begin', req, res);
|
||||
var val = pass(req, res, options, head);
|
||||
|
||||
20
lib/caronte/passes/web-outgoing.js
Normal file
20
lib/caronte/passes/web-outgoing.js
Normal file
@ -0,0 +1,20 @@
|
||||
var passes = exports;
|
||||
|
||||
/*!
|
||||
* Array of passes.
|
||||
*
|
||||
* A `pass` is just a function that is executed on `req, res, options`
|
||||
* so that you can easily add new checks while still keeping the base
|
||||
* flexible.
|
||||
*/
|
||||
|
||||
[ // <--
|
||||
function writeHeaders(res, proxyRes) {
|
||||
Object.keys(proxyRes.headers).forEach(function(key) {
|
||||
res.setHeader(key, proxyRes.headers[key]);
|
||||
});
|
||||
}
|
||||
] // <--
|
||||
.forEach(function(func) {
|
||||
passes[func.name] = func;
|
||||
});
|
||||
@ -1,8 +1,13 @@
|
||||
var http = require('http'),
|
||||
https = require('https'),
|
||||
web_o = require('./web-outgoing'),
|
||||
common = require('../common'),
|
||||
passes = exports;
|
||||
|
||||
web_o = Object.keys(web_o).map(function(pass) {
|
||||
return web_o[pass];
|
||||
});
|
||||
|
||||
/*!
|
||||
* Array of passes.
|
||||
*
|
||||
@ -100,20 +105,27 @@ function stream(req, res, options) {
|
||||
req.pipe(proxyReq);
|
||||
|
||||
proxyReq.on('response', function(proxyRes) {
|
||||
var ev = 'caronte:outgoing:web:';
|
||||
|
||||
options.ee.emit(ev + 'begin', req, res);
|
||||
|
||||
web_o.some(function(pass) {
|
||||
var evnt = ev + pass.name.toLowerCase() + ':';
|
||||
|
||||
options.ee.emit(evnt + 'begin', req, res);
|
||||
var val = pass(res, proxyRes);
|
||||
options.ee.emit(evnt + 'end');
|
||||
|
||||
return val;
|
||||
});
|
||||
|
||||
options.ee.emit(ev + 'end');
|
||||
|
||||
|
||||
proxyRes.pipe(res);
|
||||
});
|
||||
|
||||
//proxyReq.end();
|
||||
|
||||
/*if(options.forward) {
|
||||
req.pipe(new ForwardStream(options));
|
||||
}
|
||||
|
||||
if(options.target) {
|
||||
return req.pipe(new ProxyStream(options, res)).pipe(res);
|
||||
}
|
||||
|
||||
res.end();*/
|
||||
}
|
||||
|
||||
] // <--
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user