mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
chore: matches the sibling responseStream.on(aborted) handler and added tests (#7149)
Co-authored-by: Jason Saayman <jasonsaayman@gmail.com>
This commit is contained in:
@@ -912,7 +912,7 @@ export default isHttpAdapterSupported &&
|
||||
});
|
||||
|
||||
responseStream.on('error', function handleStreamError(err) {
|
||||
if (req.destroyed) return;
|
||||
if (rejected) return;
|
||||
reject(AxiosError.from(err, null, config, lastRequest, response));
|
||||
});
|
||||
|
||||
|
||||
@@ -823,6 +823,28 @@ describe('supports http with nodejs', () => {
|
||||
await stopHTTPServer(server);
|
||||
}
|
||||
});
|
||||
|
||||
it('should reject when the server aborts mid-stream and maxRedirects is 0', async () => {
|
||||
const server = await startHTTPServer(
|
||||
async (req, res) => {
|
||||
res.setHeader('Content-Encoding', type);
|
||||
res.setHeader('Transfer-Encoding', 'chunked');
|
||||
res.removeHeader('Content-Length');
|
||||
res.write(await zipped);
|
||||
setTimeout(() => res.socket.destroy(), 10);
|
||||
},
|
||||
{ port: SERVER_PORT }
|
||||
);
|
||||
|
||||
try {
|
||||
await assert.rejects(
|
||||
axios.get(`http://localhost:${server.address().port}`, { maxRedirects: 0 }),
|
||||
(err) => err && err.code === 'ECONNRESET'
|
||||
);
|
||||
} finally {
|
||||
await stopHTTPServer(server);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user