HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //var/www/quadcode.com/node_modules/needle/test/redirect_with_timeout.js
var should  = require('should')
var needle  = require('./../')

describe('follow redirects when read_timeout is set', function () {

    it('clear timeout before following redirect', function (done) {
        var opts = {
            open_timeout: 1000,
            read_timeout: 3000,
            follow: 5,
            user_agent: 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36'
        }

        var timedOut = 0
        var redirects = 0

        var timer = setTimeout(function () {
            var hasRedirects = redirects > 0
            hasRedirects.should.equal(true)
            done()
        }, opts.read_timeout || 3000)

        var resp = needle.get('http://google.com/', opts, function (err, resp, body) {
            var noErr = err === null
            var hasBody = body.length > 0
            noErr.should.equal(true);
            hasBody.should.equal(true);
        });

        resp.on('redirect', function (location) {
            redirects++
            // console.info('    Redirected to ', location)
        })

        resp.on('timeout', function (type) {
            timedOut++
            timedOut.should.equal(0)
            // console.error('   ', type, 'timeout')
            clearTimeout(timer)
            done()
        })

    }).timeout(30000)

})