fix bug related to request wrapping, where counter adopts follow value incorrectly
This commit is contained in:
parent
e574b497d5
commit
6bac50f1da
|
@ -47,7 +47,7 @@ function Request(input, init) {
|
||||||
this.compress = init.compress !== undefined ?
|
this.compress = init.compress !== undefined ?
|
||||||
init.compress : input.compress !== undefined ?
|
init.compress : input.compress !== undefined ?
|
||||||
input.compress : true;
|
input.compress : true;
|
||||||
this.counter = init.counter || input.counter || input.follow || 0;
|
this.counter = init.counter || input.counter || 0;
|
||||||
this.agent = init.agent || input.agent;
|
this.agent = init.agent || input.agent;
|
||||||
|
|
||||||
Body.call(this, init.body || this._clone(input), {
|
Body.call(this, init.body || this._clone(input), {
|
||||||
|
|
17
test/test.js
17
test/test.js
|
@ -279,7 +279,7 @@ describe('node-fetch', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should obey maximum redirect', function() {
|
it('should obey maximum redirect, reject case', function() {
|
||||||
url = base + '/redirect/chain';
|
url = base + '/redirect/chain';
|
||||||
opts = {
|
opts = {
|
||||||
follow: 1
|
follow: 1
|
||||||
|
@ -289,6 +289,17 @@ describe('node-fetch', function() {
|
||||||
.and.have.property('type', 'max-redirect');
|
.and.have.property('type', 'max-redirect');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should obey redirect chain, resolve case', function() {
|
||||||
|
url = base + '/redirect/chain';
|
||||||
|
opts = {
|
||||||
|
follow: 2
|
||||||
|
}
|
||||||
|
return fetch(url, opts).then(function(res) {
|
||||||
|
expect(res.url).to.equal(base + '/inspect');
|
||||||
|
expect(res.status).to.equal(200);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should allow not following redirect', function() {
|
it('should allow not following redirect', function() {
|
||||||
url = base + '/redirect/301';
|
url = base + '/redirect/301';
|
||||||
opts = {
|
opts = {
|
||||||
|
@ -1216,6 +1227,8 @@ describe('node-fetch', function() {
|
||||||
expect(r2.body).to.equal(form);
|
expect(r2.body).to.equal(form);
|
||||||
expect(r1.follow).to.equal(1);
|
expect(r1.follow).to.equal(1);
|
||||||
expect(r2.follow).to.equal(2);
|
expect(r2.follow).to.equal(2);
|
||||||
|
expect(r1.counter).to.equal(0);
|
||||||
|
expect(r2.counter).to.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support overwrite Request instance', function() {
|
it('should support overwrite Request instance', function() {
|
||||||
|
@ -1399,7 +1412,7 @@ describe('node-fetch', function() {
|
||||||
expect(cl.follow).to.equal(3);
|
expect(cl.follow).to.equal(3);
|
||||||
expect(cl.compress).to.equal(false);
|
expect(cl.compress).to.equal(false);
|
||||||
expect(cl.method).to.equal('POST');
|
expect(cl.method).to.equal('POST');
|
||||||
expect(cl.counter).to.equal(3);
|
expect(cl.counter).to.equal(0);
|
||||||
expect(cl.agent).to.equal(agent);
|
expect(cl.agent).to.equal(agent);
|
||||||
// clone body shouldn't be the same body
|
// clone body shouldn't be the same body
|
||||||
expect(cl.body).to.not.equal(body);
|
expect(cl.body).to.not.equal(body);
|
||||||
|
|
Loading…
Reference in New Issue