mjackson / mjackson/http-client
Content-Length header in a browser environment
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 503
- Forks
- 23
- PR merge metrics
- No merged PRs in 30d
Description
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):

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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the body method in modules/index.js around line 155 and review how the client sets Content-Length for browser requests. Compare that behavior with the fetch polyfill linked in the issue and reproduce the Safari 9.1.3 POST case; done means the browser request no longer triggers the reported header error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100