FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

http: edit _storeHeader to check for Trailer header by arturgvieira-zz · Pull Request #12990 · nodejs/node · GitHub

/ node Public

http: edit _storeHeader to check for Trailer header - #12990

Closed
arturgvieira-zz wants to merge 1 commit into
nodejs:masterfrom
arturgvieira-zz:serverHeader-branch
Closed

http: edit _storeHeader to check for Trailer header#12990
arturgvieira-zz wants to merge 1 commit into
nodejs:masterfrom
arturgvieira-zz:serverHeader-branch

Conversation

arturgvieira-zz commented May 12, 2017
edited
Loading

Copy link
Copy Markdown

Test non-chunked message does not have trailer header set,
message will be terminated by the first empty line after the
header fields, regardless of the header fields present in the
message, and thus cannot contain a message body or 'trailers'.

Ref: #2842

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

http

nodejs-github-bot added the http Issues or PRs related to the http subsystem. label May 12, 2017
arturgvieira-zz changed the title Server header branch http: edit writeHead to check for 304 and Trailer May 12, 2017
Comment thread lib/_http_server.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please avoid hasOwnProperty() for performance reasons.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What would be a better choice?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Just try accessing the property and check if it is set to anything.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thank you, will make the changes shortly.

Comment thread lib/_http_server.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This comment doesn't really describe the code below it well. The code doesn't even check for HEAD requests or 1xx/204 responses.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I will revise, thanks for the review.

Copy link
Copy Markdown
Author

@mscdex I made edits to the comment, it is more specific to the actual code.

Comment thread lib/_http_server.js Outdated

mscdex May 12, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Actually, now that I think more about it, just checking for 'Trailer' won't be enough because the letters could be in any case. I wonder if a better solution would be to just check for statusCode === 304 && state.trailer inside _storeHeader() in _http_outgoing.js? Perhaps it could be merged with the existing 204/304 check that's already being done in there.

I also don't know if we should throw or just discard the trailer header...
Thoughts @nodejs/http ?

arturgvieira-zz May 12, 2017
edited
Loading

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

All good insights. #2842 had a mention about throwing. If it is preferred to discard I'll make the change.

Copy link
Copy Markdown
Author

@mscdex All done. I updated the location of the check, thank you for pointing out _storeHeader.

arturgvieira-zz changed the title http: edit writeHead to check for 304 and Trailer http: edit _storeHeader to check for 304 and Trailer May 12, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Should the ? be a $?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes, I'll correct it. Thank you

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

common.mustCall() is not needed here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I will update it. Thanks

arturgvieira-zz commented May 12, 2017
edited
Loading

Copy link
Copy Markdown
Author

@cjihrig All done, I corrected the errors. Thanks for the review.

arturgvieira-zz commented May 17, 2017
edited
Loading

Copy link
Copy Markdown
Author

@cjihrig Hi, if you have time, could you check if I need to make any further changes?

cjihrig left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM. I'd like feedback from @nodejs/http though.

Copy link
Copy Markdown
Author

Thank you.

mscdex commented May 17, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

I've read RFC 7230 a bit more on this and my understanding/interpretation is that a Trailer header should be fine for 304 as it could indicate that a trailer would have been sent if the request was an unconditional GET (the RFC gives a similar example/explanation for a Transfer-Encoding header sent in a 304). Node already doesn't send the actual trailer for such status codes.

jasnell commented May 17, 2017

Copy link
Copy Markdown
Member

That's my understanding as well @mscdex but the spec is rather vague on the topic.

Copy link
Copy Markdown
Author

I was actually interested in closing the issue. I read over the RFC as well and I am fine with whatever you guys decide. The Bluemix story may be a concern? Thoughts.

mscdex commented May 17, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

I think the original linked issue seems to be suggesting that any Trailer header should be removed when Transfer-Encoding: chunked is not set since Trailer is a component of a chunk encoded response, regardless of status code. I guess that makes sense to me, but it'd definitely be a semver-major change IMHO.

gibfahn commented May 20, 2017
edited
Loading

Copy link
Copy Markdown
Member

The Bluemix story may be a concern? Thoughts.

@arturgvieira could you elaborate? Not sure what the Bluemix story is.

Ahh, the linked issue (#2842), got it!

refack commented May 25, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

refack self-assigned this May 25, 2017

refack commented May 25, 2017

Copy link
Copy Markdown
Contributor

I think the original linked issue seems to be suggesting that any Trailer header should be removed when Transfer-Encoding: chunked is not set since Trailer is a component of a chunk encoded response, regardless of status code. I guess that makes sense to me, but it'd definitely be a semver-major change IMHO.

@mscdex @jasnell Just to be clear, this case (304 only) is considered semver-patch?

mscdex commented May 25, 2017

Copy link
Copy Markdown
Contributor

@refack I think I'd rather just have one change for this particular issue and currently, discarding the trailer on a non-chunked response seems like the best option to me (and that would be semver-major).

refack added the blocked PRs that are blocked by other issues or PRs. label May 25, 2017

refack commented May 25, 2017

Copy link
Copy Markdown
Contributor

@refack I think I'd rather just have one change for this particular issue and currently, discarding the trailer on a non-chunked response seems like the best option to me (and that would be semver-major).

So I'm blocking this.

refack commented May 25, 2017

Copy link
Copy Markdown
Contributor

@arturgvieira go for the gold... i.e. discard the trailer for all non-chunked responses.
P.S. since headers can be added in any order I'm not sure you can do the trick you did here...

mscdex commented May 25, 2017

Copy link
Copy Markdown
Contributor

Sorry, I meant the Trailer header, actual trailer content should already be discarded for non-chunked responses.

Copy link
Copy Markdown
Author

I'm checking for lint errors.

Copy link
Copy Markdown
Author

All lint errors have been corrected.

refack commented May 25, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

@arturgvieira we don't have consensus on this fix. @mscdex and I think that you should solve the general case #12990 (comment).
That is:

  1. move the test to around L434(https://github.com/nodejs/node/pull/12990/files#diff-286202fdbdd74ede6f5f5334b6176b5cR434)
  2. Check for this.chunkedEncoding !== true && state.trailer
  3. Evaluate if response.addTrailers need modifications
  4. Document in https://github.com/nodejs/node/blob/master/doc/api/http.md#responsesetheadername-value and response.addTrailers.
  5. Expand the test.

mscdex commented May 26, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

I don't think addTrailers() needs any changes, since that content is already being ignored properly. All we should care about is skipping the Trailer header when chunked encoding is not being used. I don't think there is going to be a straight-forward change because a default chunked encoding header could be appended after the header is already generated in _storeHeader().

Copy link
Copy Markdown
Author

All done, I added the additional information for the error as requested.

refack left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

💯

refack commented Jun 11, 2017

Copy link
Copy Markdown
Contributor

refack commented Jun 12, 2017

Copy link
Copy Markdown
Contributor

/cc @nodejs/ctc

mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

refack removed the wip Issues and PRs that are still a work in progress. label Jun 12, 2017
Comment thread lib/_http_outgoing.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think this can be simplified to just throw new errors.Error(...)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Perhaps move the object literal into a separate variable and pass that to common.expectsError() to make this more readable?:

const trailerInvalidErr = {
  code: 'ERR_HTTP_TRAILER_INVALID',
  message: 'Trailers are invalid with this transfer encoding',
  type: Error
};
assert.throws(() => res.writeHead(200, {'Content-Length': '24'}),
              common.expectsError(trailerInvalidErr));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This description does not agree with the code below.

Copy link
Copy Markdown
Author

All done, made the changes requested

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Minor nit: you might add a little extra code here to verify that the response is what you expect (both statusCode and body content). In doing so, you'd need to make sure to adjust the Content-Length value to 2.

arturgvieira-zz Jun 13, 2017
edited
Loading

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ok, will do.

Copy link
Copy Markdown
Author

Made the requested changes. Thanks @mscdex

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This should just be .strictEqual().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ok

mscdex Jun 13, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Technically it would be better to just buffer data in here (without common.mustCall()) and then assert.strictEqual(buffer, 'ok') in a common.mustCall()-wrapped 'end' event handler:

var buf = '';
res.on('data', (chunk) => {
  buf += chunk;
}).on('end', common.mustCall(() => {
  assert.strictEqual(buf, 'ok');
}));

The reason being in general you shouldn't assume anything about the number of 'data' events for a stream.

Copy link
Copy Markdown
Author

@mscdex Take a look, I think this is what you meant.

mscdex Jun 13, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

IMO this is less readable, I think it's best to just always append to a variable that is initially an empty string. Also you will be able to drop the explicit buffer.toString().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ok, I just saw your edit. Changing now.

Test non-chunked message does not have trailer header set,
message will be terminated by the first empty line after the
header fields, regardless of the header fields present in the
message, and thus cannot contain a message body or 'trailers'.

Ref: #2842

Copy link
Copy Markdown
Author

@mscdex Thank you for the review.

mscdex commented Jun 13, 2017

Copy link
Copy Markdown
Contributor

mscdex commented Jun 13, 2017

Copy link
Copy Markdown
Contributor

LGTM

refack commented Jun 13, 2017

Copy link
Copy Markdown
Contributor

@jasnell PTAL (even though we have 3 CTC LGTMs)

jasnell pushed a commit that referenced this pull request Jun 13, 2017
Test non-chunked message does not have trailer header set,
message will be terminated by the first empty line after the
header fields, regardless of the header fields present in the
message, and thus cannot contain a message body or 'trailers'.

PR-URL: #12990
Ref: #2842
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>

jasnell commented Jun 13, 2017

Copy link
Copy Markdown
Member

Landed in 80c9ef0

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

http Issues or PRs related to the http subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants


Back | FazBrowse Home | New Git URL