browserify / http-browserify

node's http module, but for the browser
MIT License
244 stars 110 forks source link

String response bodies with the word ArrayBuffer in it gets destroyed #59

Closed eiriksm closed 8 years ago

eiriksm commented 10 years ago

Hello.

Just ran into this issue and it had be really stumped for a while. Since the program I am working on runs both in the browser and in node, and the response bodies with JSON were the same, I could not for the life of me figure out why I got "unexpected end of input" when the URLs, responses and everything were the same. The reason was that if a string response holds the exact phrase "ArrayBuffer" that particular buffer will be converted into a Uint8Array (ref https://github.com/substack/http-browserify/blob/c0869e5f1d57eac1ce12305e226eadf82b052e07/lib/response.js#L107)

For a POC, I have put together this page: https://eiriksm.github.io/browserify-test (read the console and watch the network tab for what it was supposed to look like).

Now, I didn't come here just to complain, so I tried to make a solution to this in a PR coming in 2 seconds. I am not 100% sure how this is supposed to be used, but at least it worked when I was sending buffers from a http.createServer. But as I said, I am not 100% sure how it is supposed to work, so corrections are of course welcome. The actual line of code is based on the style that follows in the next function in the file the patch alters (isArray)

eiriksm commented 10 years ago

...oh, and just so I don't forget to mention this: Thanks alot for making browserify! I can't imagine starting a project without it now.

eiriksm commented 8 years ago

Closing (ref #60)