ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.56k stars 1.33k forks source link

Binary response data parsed as text #1681

Closed lance closed 2 years ago

lance commented 2 years ago

Hello, I have an endpoint that may return binary data which is not an image or a video. The response headers include the correct content type, audio/aac for example, and the correct content-length header. However, when the response is received by the client, the response body is empty, and instead response.txt contains the returned data. I've tracked it down to this code block in Request.prototype._end(). https://github.com/visionmedia/superagent/blob/84206c75214e20bbc688d0645880696ecd773c27/src/node/index.js#L1082-L1084

It is unclear to me why the parser would necessarily be text in this case. I find that by changing this so that the fallback always uses exports.parse.image, my use case succeeds but results in 9 failed tests.

I am using superagent via visionmedia/supertest, in case that makes a difference.