Skip to content

Commit cd6737f

Browse files
chore: matches the sibling responseStream.on(aborted) handler and added tests (#7149)
Co-authored-by: Jason Saayman <jasonsaayman@gmail.com>
1 parent 9fcdf48 commit cd6737f

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

lib/adapters/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ export default isHttpAdapterSupported &&
912912
});
913913

914914
responseStream.on('error', function handleStreamError(err) {
915-
if (req.destroyed) return;
915+
if (rejected) return;
916916
reject(AxiosError.from(err, null, config, lastRequest, response));
917917
});
918918

tests/unit/adapters/http.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,28 @@ describe('supports http with nodejs', () => {
823823
await stopHTTPServer(server);
824824
}
825825
});
826+
827+
it('should reject when the server aborts mid-stream and maxRedirects is 0', async () => {
828+
const server = await startHTTPServer(
829+
async (req, res) => {
830+
res.setHeader('Content-Encoding', type);
831+
res.setHeader('Transfer-Encoding', 'chunked');
832+
res.removeHeader('Content-Length');
833+
res.write(await zipped);
834+
setTimeout(() => res.socket.destroy(), 10);
835+
},
836+
{ port: SERVER_PORT }
837+
);
838+
839+
try {
840+
await assert.rejects(
841+
axios.get(`http://localhost:${server.address().port}`, { maxRedirects: 0 }),
842+
(err) => err && err.code === 'ECONNRESET'
843+
);
844+
} finally {
845+
await stopHTTPServer(server);
846+
}
847+
});
826848
});
827849
}
828850
});

0 commit comments

Comments
 (0)