mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[test] add test for forwardstream
This commit is contained in:
parent
f4e9945856
commit
8fc3389367
@ -13,15 +13,16 @@ var common = exports;
|
||||
* @param {Object} Outgoing Base object to be filled with required properties
|
||||
* @param {Object} Options Config object passed to the proxy
|
||||
* @param {ClientRequest} Req Request Object
|
||||
* @param {String} Forward String to select forward or target
|
||||
*
|
||||
* @return {Object} Outgoing Object with all required properties set
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
common.setupOutgoing = function(outgoing, options, req) {
|
||||
common.setupOutgoing = function(outgoing, options, req, forward) {
|
||||
['host', 'hostname', 'port', 'socketPath'/*, 'agent'*/].forEach(
|
||||
function(e) { outgoing[e] = options.target[e]; }
|
||||
function(e) { outgoing[e] = options[forward || 'target'][e]; }
|
||||
);
|
||||
|
||||
['method', 'path', 'headers'].forEach(
|
||||
|
||||
@ -33,7 +33,6 @@ function createRightProxy(type) {
|
||||
return function(req, res) {
|
||||
var self = this,
|
||||
ev = 'caronte:' + type + ':';
|
||||
|
||||
//self.emit(ev + 'begin', req, res);
|
||||
|
||||
passes.forEach(function(pass) {
|
||||
|
||||
@ -50,8 +50,8 @@ require('util').inherits(ForwardStream, Writable);
|
||||
*/
|
||||
|
||||
ForwardStream.prototype.onPipe = function(request) {
|
||||
this.forwardReq = (options.ssl ? https : http).request(
|
||||
common.setupOutgoing(options.ssl || {}, options, request)
|
||||
this.forwardReq = (this.options.ssl ? https : http).request(
|
||||
common.setupOutgoing(this.options.ssl || {}, this.options, request, 'forward')
|
||||
);
|
||||
|
||||
this.forwardReq.on('error', function() {}); /** Fire and forget */
|
||||
@ -85,4 +85,4 @@ ForwardStream.prototype.onFinish = function() {
|
||||
|
||||
ForwardStream.prototype._write = function(chunk, encoding, clb) {
|
||||
this.forwardReq.write(chunk, encoding, clb);
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
var ForwardStream = require('../lib/caronte/streams/forward'),
|
||||
var caronte = require('../'),
|
||||
ForwardStream = require('../lib/caronte/streams/forward');
|
||||
expect = require('expect.js'),
|
||||
Writable = require('stream').Writable,
|
||||
http = require('http');
|
||||
@ -22,16 +23,23 @@ describe('lib/caronte/passes/web.js', function () {
|
||||
});
|
||||
|
||||
describe('should pipe the request and finish it', function () {
|
||||
it('should make the request on pipe and finish it');
|
||||
var stubOptions = {
|
||||
target: {
|
||||
hostname : 'www.google.com',
|
||||
port : '80',
|
||||
path : '/'
|
||||
}
|
||||
};
|
||||
it('should make the request on pipe and finish it', function(done) {
|
||||
var result;
|
||||
|
||||
var p = caronte.createProxyServer({
|
||||
forward: 'http://127.0.0.1:8080'
|
||||
}).listen('8081')
|
||||
|
||||
var forwardProxy = new ForwardStream({});
|
||||
var s = http.createServer(function(req, res) {
|
||||
expect(req.method).to.eql('GET');
|
||||
s.close();
|
||||
p.close();
|
||||
done();
|
||||
});
|
||||
|
||||
s.listen('8080');
|
||||
|
||||
http.request('http://127.0.0.1:8081', function() {}).end();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user