fix: improve redirect behavior in protocol module (#26297)

* fix: improve redirect behavior in protocol module

* Add test for redirection

Co-authored-by: Cheng Zhao <zcbenz@gmail.com>
This commit is contained in:
David Sanders 2021-01-19 02:06:14 -08:00 committed by GitHub
parent 4334110339
commit 5e7e0a4c7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 11 deletions

View file

@ -671,6 +671,26 @@ describe('protocol module', () => {
const r = await ajax('http://fake-host');
expect(r.data).to.equal('redirect');
});
it('should discard post data after redirection', async () => {
interceptStreamProtocol('http', (request, callback) => {
if (request.url.indexOf('http://fake-host') === 0) {
setTimeout(() => {
callback({
statusCode: 302,
headers: {
Location: 'http://fake-redirect'
}
});
}, 300);
} else {
expect(request.url.indexOf('http://fake-redirect')).to.equal(0);
callback(getStream(3, request.method));
}
});
const r = await ajax('http://fake-host', { type: 'POST', data: postData });
expect(r.data).to.equal('GET');
});
});
describe('protocol.uninterceptProtocol', () => {