★ wanayoo — archive 1999 https://github.com/nodejs/node/pull/26465Nouvelle recherche | Portail wanayoo
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

doc: fix misleading sentence in http.md #26465

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
9 participants
@lpinca
Copy link
Member

lpinca commented Mar 6, 2019

Calling response.end(data) is not 100% equivalent to calling
response.write(data) followed by response.end().

Fixes: #26005

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • documentation is changed or added
  • commit message follows commit guidelines
@ZYSzys

ZYSzys approved these changes Mar 6, 2019

[`response.write(data, encoding)`][] followed by `response.end(callback)`. There
is, however, a difference in the headers that are sent by default. If
[`response.write()`][] is used, the `Transfer-Encoding` header is set to
`chunked`, otherwise the `Transfer-Encoding` header is replaced by the

This comment has been minimized.

@vsemozhetbyt

vsemozhetbyt Mar 6, 2019

Member

Nit:

Suggested change
`chunked`, otherwise the `Transfer-Encoding` header is replaced by the
`'chunked'`, otherwise the `Transfer-Encoding` header is replaced by the

This comment has been minimized.

@Trott

Trott Mar 6, 2019

Member

Optional suggestion: Change the comma to a period and make the Otherwise clause its own sentence.

@richardlau

This comment has been minimized.

Copy link
Member

richardlau commented Mar 6, 2019

Commit message has misspelled sentence.

@lpinca lpinca force-pushed the lpinca:gh-26005 branch from ebb49fa to 286f7ab Mar 6, 2019

is, however, a difference in the headers that are sent by default. If
[`response.write()`][] is used, the `Transfer-Encoding` header is set to
`'chunked'`. Otherwise the `Transfer-Encoding` header is replaced by the
`Content-Length` header.

This comment has been minimized.

@sam-github

sam-github Mar 6, 2019

Member

I think this leaves one case undescribed: response.write(data); response.end(data)

Also, while accurate, so an improvement, I think its too low level, it doesn't give any idea why its done this way. And if you knew why, then you wouldn't need the docs.

I'd suggest that the .write() docs be modified to say that because .write() can be called multiple times, the size of the entire response (or request, I suspect these docs apply to both req and response) cannot be known when .write() is called, so HTTP will use chunked transfer encoding, and there will not be a content-size header.

In .end(), I'd say that if .write() has not previously been called, the total size is known (zero, or the size of the data arg), so node.js doesn't have to (and won't) use chunked transfer encoding, and it will write a content-length header. In other cases, since chunked transfer has already begun, any data provided to .end() will be transferred as a chunk.

^--- I think this is accurate, and describes why this is, and makes this seem less like a weird gotcha, and more like a feature: that if you have one large chunk that can be written in a single call to .end(), you can cause the content-size to be set and chunked mode not to be used. I'm not sure if it applies equally to the writing of requests, and the writing of responponses... but it should!

This comment has been minimized.

@lpinca

lpinca Mar 6, 2019

Author Member

I only wanted to address the misleading sentence quoted in #26005 and not describe chunk mode. This is also not 100% accurate as the user could explicitly specify Content-Length disabling the default chunked mode. Perhaps it's simpler to just remove that sentence?

This comment has been minimized.

@sam-github

sam-github Mar 6, 2019

Member

It would be nice to have the info about how explicitly setting the header changes things. Basically, that Node.js has good support for chunked mode (unlike a number of crappy HTTP APIs I've come across), is a wonderful feature, its a shame we don't document it better.

Your comment above makes me wonder if your proposed text is accurate/complete, doesn't it suffer the same problem?

For now, yes, I think rather than dumping in the detail you proposed, if you aren't up to a really comprehensive treatment, just changing "the same as" to "similar in effect to", or similar weasel words, might make the docs "not wrong", even though it still leaves streaming vs non-streaming mode undoced.

This comment has been minimized.

@lpinca

lpinca Mar 6, 2019

Author Member

Your comment above makes me wonder if your proposed text is accurate/complete, doesn't it suffer the same problem?

Yes, I've added "the headers that are sent by default" to address that but I guess it's not clear.

I will change this tomorrow and use "similar" removing all the chunked mode info.
FWIW the request counterparts are slightly better documented.

@sam-github sam-github changed the title doc: fix misleading sentece in http.md doc: fix misleading sentence in http.md Mar 6, 2019

@sam-github

This comment has been minimized.

Copy link
Member

sam-github commented Mar 6, 2019

nit: I think a commit message of doc: describe when chunked mode is used would be more descriptive of the specific change being made.

@jasnell

jasnell approved these changes Mar 7, 2019

doc: fix misleading sentence in http.md
Calling `response.end(data)` is not 100% equivalent to calling
`response.write(data)` followed by `response.end()`.

Fixes: #26005

@lpinca lpinca force-pushed the lpinca:gh-26005 branch from 286f7ab to f80563f Mar 7, 2019

@lpinca

This comment has been minimized.

Copy link
Member Author

lpinca commented Mar 7, 2019

Folks that approved this, PTAL, I've updated as per @sam-github suggestion.

Abstain

@BridgeAR

This comment has been minimized.

Copy link
Member

BridgeAR commented Mar 7, 2019

I would rather have a detailed information but I won't block this either.

@lpinca

This comment has been minimized.

Copy link
Member Author

lpinca commented Mar 7, 2019

It makes sense but I don't have the energy to update the docs as suggested in #26465 (comment) explaining how and when chunked mode is used, how to disable it, etc. especially due to all the nit picking that will come from that.

If that is preferred I would prefer it to be done by a native speaker.

@BridgeAR

This comment has been minimized.

Copy link
Member

BridgeAR commented Mar 12, 2019

What should be done here?

@jasnell PTAL

BridgeAR added a commit to BridgeAR/node that referenced this pull request Mar 13, 2019

doc: fix misleading sentence in http.md
Calling `response.end(data)` is not 100% equivalent to calling
`response.write(data)` followed by `response.end()`.

PR-URL: nodejs#26465
Fixes: nodejs#26005
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
@BridgeAR

This comment has been minimized.

Copy link
Member

BridgeAR commented Mar 13, 2019

Landed in 1706a2d 🎉

@BridgeAR BridgeAR closed this Mar 13, 2019

@lpinca lpinca deleted the lpinca:gh-26005 branch Mar 13, 2019

BridgeAR added a commit that referenced this pull request Mar 14, 2019

doc: fix misleading sentence in http.md
Calling `response.end(data)` is not 100% equivalent to calling
`response.write(data)` followed by `response.end()`.

PR-URL: #26465
Fixes: #26005
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>

BridgeAR added a commit to BridgeAR/node that referenced this pull request Mar 14, 2019

doc: fix misleading sentence in http.md
Calling `response.end(data)` is not 100% equivalent to calling
`response.write(data)` followed by `response.end()`.

PR-URL: nodejs#26465
Fixes: nodejs#26005
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>

BridgeAR added a commit that referenced this pull request Mar 14, 2019

doc: fix misleading sentence in http.md
Calling `response.end(data)` is not 100% equivalent to calling
`response.write(data)` followed by `response.end()`.

PR-URL: #26465
Fixes: #26005
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>

Drieger added a commit to Drieger/node that referenced this pull request Mar 22, 2019

doc: fix misleading sentence in http.md
Calling `response.end(data)` is not 100% equivalent to calling
`response.write(data)` followed by `response.end()`.

PR-URL: nodejs#26465
Fixes: nodejs#26005
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.