1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #2126 from natcl/master

http request node: warn user if msg.requestTimeout == 0
This commit is contained in:
Nick O'Leary 2019-05-17 10:47:37 +01:00 committed by GitHub
commit 91473e731e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -94,10 +94,10 @@ module.exports = function(RED) {
opts.maxRedirects = 21; opts.maxRedirects = 21;
opts.jar = request.jar(); opts.jar = request.jar();
opts.proxy = null; opts.proxy = null;
if (msg.requestTimeout) { if (msg.requestTimeout !== undefined) {
if (isNaN(msg.requestTimeout)) { if (isNaN(msg.requestTimeout)) {
node.warn(RED._("httpin.errors.timeout-isnan")); node.warn(RED._("httpin.errors.timeout-isnan"));
} else if (msg.requestTimeout < 0) { } else if (msg.requestTimeout < 1) {
node.warn(RED._("httpin.errors.timeout-isnegative")); node.warn(RED._("httpin.errors.timeout-isnegative"));
} else { } else {
opts.timeout = msg.requestTimeout; opts.timeout = msg.requestTimeout;

View File

@ -979,6 +979,29 @@ describe('HTTP Request Node', function() {
n1.receive({payload:"foo", requestTimeout: -4}); n1.receive({payload:"foo", requestTimeout: -4});
}); });
}); });
it('should show a warning if msg.requestTimeout is set to 0', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/text')},
{id:"n2", type:"helper"}];
helper.load(httpRequestNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('statusCode', 200);
var logEvents = helper.log().args.filter(function(evt) {
return evt[0].type == 'http request';
});
logEvents.should.have.length(2);
var tstmp = logEvents[0][0].timestamp;
logEvents[0][0].should.eql({level:helper.log().WARN, id:'n1',type:'http request',msg:'httpin.errors.timeout-isnegative', timestamp:tstmp});
done();
} catch(err) {
done(err);
}
});
n1.receive({payload:"foo", requestTimeout: 0});
});
});
it('should pass if response time is faster than timeout set via msg.requestTimeout', function(done) { it('should pass if response time is faster than timeout set via msg.requestTimeout', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/timeout50ms')}, var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/timeout50ms')},
{id:"n2", type:"helper"}]; {id:"n2", type:"helper"}];