Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set transfer encoding for multipart/related to chunked by default #1276

Merged
merged 3 commits into from Nov 20, 2014

Conversation

simov
Copy link
Member

@simov simov commented Nov 18, 2014

Fixes #1271

Also added a test for GET request.

Basically the test for this feature is

if (chunked) {
  t.ok(req.headers['transfer-encoding'] === 'chunked')
  t.notOk(req.headers['content-length'])
}

Inside the end event of the request there is no body when GET request is being used.

@simov
Copy link
Member Author

simov commented Nov 18, 2014

@triccardi-systran can you take a look at this as well?

@nylen
Copy link
Member

nylen commented Nov 18, 2014

Inside the end event of the request there is no body when GET request is being used.

Why not?

@simov
Copy link
Member Author

simov commented Nov 18, 2014

@nylen I think you are correct, at some point I didn't received anything, but I tested a few things along the way, will push.

EDIT: saw that will change it 👍

@simov
Copy link
Member Author

simov commented Nov 18, 2014

@nylen all done, fixed my PR description as well.

@nylen
Copy link
Member

nylen commented Nov 18, 2014

Here is the reason (in Node http module) for Transfer-Encoding: chunked not being set on GET requests:

It looks to me like this is a heuristic which we can override if we assume the user knows what they're doing and really wants to send a chunked GET. Note that it applies to different methods over time (GET, HEAD at first; then CONNECT, DELETE, and OPTIONS added later on).

So, 👍 from me, but would like feedback from @triccardi-systran on whether this fixes his issue.

@thomas-riccardi
Copy link

Okay, this seems fine to me!
I confirm this fixes all the scenarios & related issues I reported in #758 and #1271.

Just one question: how do we guarantee that node.js http will not send in chunks anyway when we have chunked = false?
It seems we currently rely on the node.js http heuristics that choose well currently, but can we rely on that for the future? Is there a way to force no chunk?

@simov
Copy link
Member Author

simov commented Nov 20, 2014

If the multipart option contains a chunked key explicitly set to false then the multipart/related parts are pushed into array and assigned to self.body inside the multipart method.

Then here self.body is an Array, and therefore the content-length header is always set.

Having the content-length header set means that you can't have a chunked encoding at the same time (as far as I understand the spec)

@nylen
Copy link
Member

nylen commented Nov 20, 2014

Here's the relevant core code: lib/http.js#L630

@simov do we have a test to make sure there is only one of content-length and transfer-encoding headers, not both?

@simov
Copy link
Member Author

simov commented Nov 20, 2014

@nylen you refer to the the scenario where the user sets the content-length header and at the same time doesn't set the chunked key to false explicitly? If that's the scenario you are referring to, then no, currently there is no such check. And I can't think of any other possible scenario.

@nylen
Copy link
Member

nylen commented Nov 20, 2014

Ah, it's in there. I was thinking of this: https://github.com/simov/request/blob/multipart-get/tests/test-multipart.js#L28

@nylen
Copy link
Member

nylen commented Nov 20, 2014

Thanks @triccardi-systran and @simov for your work on this!

nylen added a commit that referenced this pull request Nov 20, 2014
Set transfer encoding for multipart/related to chunked by default
@nylen nylen merged commit e543acf into request:master Nov 20, 2014
@thomas-riccardi
Copy link

@simov I tested this case, and since request always adds the chunked header, node http will encode in chunks, and we will get a HTTP request chunked encoded that also has a content-length header. This is an invalid HTTP request according to rfc2616 section 4.4.
Maybe we should check for content-length header before forcing chunked encoding.

@nylen
Copy link
Member

nylen commented Nov 20, 2014

I don't think we can or should guard against every combination of impossible settings, this one in particular is obviously user error.

@thomas-riccardi
Copy link

This is not obviously a user error since the user doesn't know that multipart is chunked encoded by default (since it's a default).
However, in this particular case, the user cannot know the real content-length since it's request that generates the boundary for the multipart, so we can assume it's indeed invalid.

@simov simov mentioned this pull request Nov 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stream multipart/related is broken: missing chunked encoding for default GET method.
3 participants