Axios hangs when POST an empty buffer
See original GitHub issueSummary
When sending a ‘POST’ or ‘PUT’ request with an empty buffer, the promise doesn’t resolve or reject and the server doesn’t get the request. The following example demonstrates the issue:
const axios = require('axios');
const http = require('http');
const server = http.createServer((req, res) => {
console.log('received request');
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('okay');
});
['listening', 'error', 'connection', 'close'].forEach(ev => {
server.on(ev, function() {
console.log(ev);
});
});
server.listen(7373, async () => {
await axios({
url: `http://localhost:7373/hb`,
method: 'post',
data: Buffer.from(''),
});
await server.close();
});
The output for the above is:
listening
connection
and the process hangs. If you replace Buffer.from('')
with just ''
then it works properly and the output is:
listening
connection
request received
close
Context
- axios version: 0.18.0
- Environment: node v10.6.0
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Send back Buffer Object to Axios leads to an Error
Anyhow, I've run into this issue before when trying to upload binary. The solution I found was to pass set maxRedirects to 0...
Read more >Send a File With Axios in Node.js - Maxim Orlov
In this article, you'll learn how to send files and associated data by constructing a form. We'll cover the two file types —...
Read more >Axios vs. fetch(): Which is best for making HTTP requests?
To send data, fetch() uses the body property for a post request to send data to the endpoint, while Axios uses the data...
Read more >How to handle error message and binary response with Axios ...
But how to, as Axios will convert responses according to your specific response type? The answer is specifying response type as ArrayBuffer rather...
Read more >React file upload: proper and easy way, with NodeJS!
Create form object and create POST request with axios . It needs endpoint URL and ... Here are situations where this application can...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fantastic work, thank you so much 😃
Ruben, the person who opened the issue is also the biggest contributor of
follow-redirects
. So when I made my PR to the module, he was curious if it was solely related to follow-redirects or directly to Node. When he discovered that it was directly related to Node he decided to open up an issue 😃 .