axios: Axios not receiving 204 response with Transfer-Encoding header in Node v14
Describe the bug
After upgrading our node version to v14.15.1 our Axios requests in our express server never receive a response from an endpoint that returns 204 with header: ‘Transfer-Encoding’: ‘chunked’. I know we should not be receiving this (see here) but we do not have control of this endpoint.
Previously when we were on v10.23.0 of node we had no problem with receiving these responses.
I have tried the same request with the request library and am able to receive a response. See example below.
To Reproduce
Created a simple express server to demonstrate.
npm install axios express request
With the following index.js
Sending a GET request to http://localhost:8555/request will return 200 OK, whereas the request to http://localhost:8555/ will timeout/never receive a response.
const express = require('express');
const axios = require('axios');
const request = require('request');
const httpPort = 8555;
const app = express();
app.get('/', async (req, res, next) => {
try {
const result = await axios.get(`http://localhost:${httpPort}/sample-upstream-response`, {
timeout: 10000,
});
res.send(result.data);
} catch (error) {
res.sendStatus(500);
}
});
app.get('/request', (req, res, next) => {
request(`http://localhost:${httpPort}/sample-upstream-response`, { json: true }, (err, response, body) => {
if (err) {
return res.sendStatus(500);
}
res.send(body);
});
});
app.get('/sample-upstream-response', (req, res, next) => {
res.writeHead(204, {
'Transfer-Encoding': 'chunked',
});
res.end();
});
app.listen(httpPort, () => {
console.log(`INFO: listening on http://localhost:${httpPort}`);
});
Expected behavior
I am expecting that Axios should be able to receive the response from this server. Or I should be able to change some axios config to be able to receive this response.
Environment
- Axios Version 0.21.0
- Node.js Version 14.15.1
- OS: Windows 10, ubuntu 18.04
- Additional Library Versions express 4.17.1, request 2.88.2
Additional context/Screenshots
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 18 (1 by maintainers)
Is this going to be addressed? this ticket has been open for 2 years
It was very painful. I wasted my time on this.
Yes, Same issue i am also facing with Node v14
After upgrading to v14, i am not getting response back in UI. However the node js sending the response (debugged till last step).
Also, if i hit the api via postman, it is getting response. Also if i hit this api via “Open Link in New Tab” option click, then also getting response back
Only in the application (where i am using axios), the response is not coming back. The status in console is keep on “Pending”.