http-client icon indicating copy to clipboard operation
http-client copied to clipboard

Content-Length header in a browser environment

Open jdmunro opened this issue 9 years ago • 4 comments

I've been using this client to perform basic HTTP POST requests in a browser environment. I noticed this error in my console (Safari 9.1.3):

screen shot 2016-10-17 at 15 55 54

It seems to be expected that this header will be automatically set by the browser's runtime environment and not by the application-level code for security reasons.

Taking a look at the source-code for the body method, we do indeed set the Content-Length property: https://github.com/mjackson/http-client/blob/master/modules/index.js#L155

However, what's not clear to me whether this special-case should be handled by this library or within the fetch polyfill (I'm using: https://github.com/github/fetch)

Any thoughts?

PS thanks for the great library!

jdmunro avatar Oct 18 '16 16:10 jdmunro

Is this an error or a warning? Do you know if it happens in other browsers as well? I haven't seen anything like this in Chrome.

If possible, I'd like to keep the behavior here because it's especially useful when using http-client in node. But if it's causing browsers to throw then we should probably remove it.

mjackson avatar Nov 25 '16 03:11 mjackson

Hi!

Unfortunately, we've encountered that bug, on Safari, as well.

Augustin82 avatar Dec 15 '16 13:12 Augustin82

I'll test this out in Chrome later this week - I'm fairly sure it had the same issue though perhaps manifested slightly differently.

jdmunro avatar Dec 15 '16 13:12 jdmunro

Here, we have no problem on Chrome on Linux (which is our main dev platform), but it crashed on the first Safari test run :)

Augustin82 avatar Dec 15 '16 13:12 Augustin82