question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Axios hangs when POST an empty buffer

See original GitHub issue

Summary

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:closed
  • Created 5 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
amitzurcommented, Aug 1, 2018

Fantastic work, thank you so much 😃

0reactions
anthonygauthiercommented, Aug 1, 2018

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 😃 .

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found