mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	http request node: warn user if msg.requestTimeout == 0
This commit is contained in:
		@@ -94,10 +94,10 @@ module.exports = function(RED) {
 | 
			
		||||
            opts.maxRedirects = 21;
 | 
			
		||||
            opts.jar = request.jar();
 | 
			
		||||
            opts.proxy = null;
 | 
			
		||||
            if (msg.requestTimeout) {
 | 
			
		||||
            if (msg.requestTimeout !== undefined) {
 | 
			
		||||
                if (isNaN(msg.requestTimeout)) {
 | 
			
		||||
                    node.warn(RED._("httpin.errors.timeout-isnan"));
 | 
			
		||||
                } else if (msg.requestTimeout < 0) {
 | 
			
		||||
                } else if (msg.requestTimeout < 1) {
 | 
			
		||||
                    node.warn(RED._("httpin.errors.timeout-isnegative"));
 | 
			
		||||
                } else {
 | 
			
		||||
                    opts.timeout = msg.requestTimeout;
 | 
			
		||||
 
 | 
			
		||||
@@ -979,6 +979,29 @@ describe('HTTP Request Node', function() {
 | 
			
		||||
                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) {
 | 
			
		||||
            var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/timeout50ms')},
 | 
			
		||||
                {id:"n2", type:"helper"}];
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user