diff --git a/lib/caronte/streams/forward.js b/lib/caronte/streams/forward.js index 7ab8028..b7e8ccd 100644 --- a/lib/caronte/streams/forward.js +++ b/lib/caronte/streams/forward.js @@ -21,12 +21,16 @@ module.exports = ForwardStream; */ function ForwardStream() { + var self = this; + Writable.call(this); - this.once('pipe', this.onPipe); - this.once('finish', this.onFinish); + this.once('pipe', function() { self.onPipe() }); + this.once('finish', function() { self.onFinish() }); } +require('util').inherits(ForwardStream, Writable); + /** * Fires up the request to the external target * @@ -74,6 +78,4 @@ ForwardStream.prototype.onFinish = function() { ForwardStream.prototype._write = function(chunk, encoding, clb) { this.forwardReq.write(chunk, encoding, clb); -}; - -require('util').inherits(ForwardStream, Writable); \ No newline at end of file +}; \ No newline at end of file diff --git a/package.json b/package.json index 8cef91a..e2b3f25 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "scripts" : { "blanket" : { "pattern": "caronte/lib" }, - "test" : "mocha -R spec test/*-test.js && npm run-script test-cov", + "test" : "mocha -R landing test/*-test.js", "test-cov" : "mocha --require blanket -R html-cov > cov/coverage.html" }, diff --git a/test/lib-caronte-common-test.js b/test/lib-caronte-common-test.js new file mode 100644 index 0000000..b489c9f --- /dev/null +++ b/test/lib-caronte-common-test.js @@ -0,0 +1,33 @@ +var common = require('../lib/caronte/common'), + expect = require('expect.js'); + +describe('lib/caronte/common.js', function() { + describe('#setupOutgoing', function() { + it('should setup the right headers', function() { + var outgoing = {}; + common.setupOutgoing(outgoing, + { + host : 'hey', + hostname : 'how', + socketPath: 'are', + port : 'you', + agent : '?' + }, + { + method : 'i', + path : 'am', + headers : 'proxy' + }); + + expect(outgoing.host).to.eql('hey'); + expect(outgoing.hostname).to.eql('how'); + expect(outgoing.socketPath).to.eql('are'); + expect(outgoing.port).to.eql('you'); + expect(outgoing.agent).to.eql('?'); + + expect(outgoing.method).to.eql('i'); + expect(outgoing.path).to.eql('am'); + expect(outgoing.headers).to.eql('proxy') + }); + }); +}); \ No newline at end of file