Skip to content

Transfer encoding in HTTP headers #47

@danielstocks

Description

@danielstocks

Hello,

It seems that window.fetch in the browser will treat Content-Length and Transfer-Encoding differently compared to node-fetch. This causes some headache as a receiving server will have to treat these results differently (stream vs no stream).

This is how I'm calling fetch (both on the client and the server)

fetch("http://localhost:5000/users", { method: "POST" });

Using node-fetch in Node 4.1 yields the following headers on the receiving server:

Transfer-Encoding: chunked
Content-Length:

Where as using window.fetch in Chrome 45.0.2454.85 produces the following:

Content-Length: 0

I'm not sure about this, but my guess is that Transfer-Encoding: chunkedshould only be applied in the cases where you're providing a stream as body. As in this instance: https://github.com/bitinn/node-fetch/blob/master/test/test.js#L436

Otherwise, it should set the content-length header. I.e something like this:

options.headers['Content-Length'] = Buffer.byteLength(body);

I may have misunderstood the spec, so let me know if this fits within the scope of this project or not. If so, I'm happy to submit a PR.

Regards,
Daniel

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions