mjackson / mjackson/http-client

Content-Length header in a browser environment

Open
#35 4 comments 0 reactions 0 assignees View on GitHub

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):

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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.