Last change
on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | var should = require('should')
|
---|
2 | var needle = require('./../')
|
---|
3 |
|
---|
4 | describe('follow redirects when read_timeout is set', function () {
|
---|
5 |
|
---|
6 | it('clear timeout before following redirect', function (done) {
|
---|
7 | var opts = {
|
---|
8 | open_timeout: 1000,
|
---|
9 | read_timeout: 3000,
|
---|
10 | follow: 5,
|
---|
11 | 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'
|
---|
12 | }
|
---|
13 |
|
---|
14 | var timedOut = 0
|
---|
15 | var redirects = 0
|
---|
16 |
|
---|
17 | var timer = setTimeout(function () {
|
---|
18 | var hasRedirects = redirects > 0
|
---|
19 | hasRedirects.should.equal(true)
|
---|
20 | done()
|
---|
21 | }, opts.read_timeout || 3000)
|
---|
22 |
|
---|
23 | var resp = needle.get('http://google.com/', opts, function (err, resp, body) {
|
---|
24 | var noErr = err === null
|
---|
25 | var hasBody = body.length > 0
|
---|
26 | noErr.should.equal(true);
|
---|
27 | hasBody.should.equal(true);
|
---|
28 | });
|
---|
29 |
|
---|
30 | resp.on('redirect', function (location) {
|
---|
31 | redirects++
|
---|
32 | // console.info(' Redirected to ', location)
|
---|
33 | })
|
---|
34 |
|
---|
35 | resp.on('timeout', function (type) {
|
---|
36 | timedOut++
|
---|
37 | timedOut.should.equal(0)
|
---|
38 | // console.error(' ', type, 'timeout')
|
---|
39 | clearTimeout(timer)
|
---|
40 | done()
|
---|
41 | })
|
---|
42 |
|
---|
43 | }).timeout(30000)
|
---|
44 |
|
---|
45 | }) |
---|
Note:
See
TracBrowser
for help on using the repository browser.