diff --git a/test/protocol.js b/test/protocol.js index f0ec8ef..d577906 100644 --- a/test/protocol.js +++ b/test/protocol.js @@ -495,55 +495,55 @@ describe('http proxy', function () { }); }); -// describe('beforeRequest hook', function () { -// it('should trigger before request', function (done) { -// var getTest = require('./protocol/http_protocol_get_test.js'); -// // start a http server for get -// var server = getTest.createServer(); -// var httpProtocol = new HttpProtocol(); -// var context = HttpProtocol.normalizeConfig(getTest.service); -// context.path = '/gziperror'; -// context.disableGzip = false; -// context.beforeRequest = function (context) { -// context.server.port.should.be.eql(8934); -// context.server.host.should.be.eql('127.0.0.1'); -// return context; -// } -// util.merge(context, getTest.request); -// httpProtocol.talk(context, function (res) { -// res.on('end', function (data) { -// server.close(); -// data.toString().should.not.be.ok; -// done(); -// }); -// res.on('error', function (err) { -// server.close(); -// err.message.should.be.match(/unexpected end of file/); -// done(); -// }); -// }); -// }); - -// it('should cancel request by return false', function () { -// var getTest = require('./protocol/http_protocol_get_test.js'); -// // start a http server for get -// // var server = getTest.createServer(); -// var httpProtocol = new HttpProtocol(); -// var context = HttpProtocol.normalizeConfig(getTest.service); -// context.path = '/gziperror'; -// context.disableGzip = false; -// context.beforeRequest = function (context) { -// return false; -// } -// util.merge(context, getTest.request); -// try { -// httpProtocol.talk(context); -// } catch (ex) { -// // server.close(); -// ex.message.toString().should.be.eql('Request was canceled by beforeRequest hook since returned context was false'); -// } -// }); -// }); +describe('beforeRequest hook', function () { + it('should trigger before request', function (done) { + var getTest = require('./protocol/http_protocol_get_test.js'); + // start a http server for get + var server = getTest.createServer(); + var httpProtocol = new HttpProtocol(); + var context = HttpProtocol.normalizeConfig(getTest.service); + context.path = '/gziperror'; + context.disableGzip = false; + context.beforeRequest = function (context) { + context.server.port.should.be.eql(8934); + context.server.host.should.be.eql('127.0.0.1'); + return context; + } + util.merge(context, getTest.request); + httpProtocol.talk(context, function (res) { + res.on('end', function (data) { + server.close(); + data.toString().should.not.be.ok; + done(); + }); + res.on('error', function (err) { + server.close(); + err.message.should.be.match(/unexpected end of file/); + done(); + }); + }); + }); + + it('should cancel request by return false', function () { + var getTest = require('./protocol/http_protocol_get_test.js'); + // start a http server for get + // var server = getTest.createServer(); + var httpProtocol = new HttpProtocol(); + var context = HttpProtocol.normalizeConfig(getTest.service); + context.path = '/gziperror'; + context.disableGzip = false; + context.beforeRequest = function (context) { + return false; + } + util.merge(context, getTest.request); + try { + httpProtocol.talk(context); + } catch (ex) { + // server.close(); + ex.message.toString().should.be.eql('Request was canceled by beforeRequest hook since returned context was false'); + } + }); +}); describe('soap protocol', function () { it.skip('should request wsdl service successfully', function (done) {