-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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: explain HTTP writeHead()'s fast path behavior #21289
Conversation
@gireeshpunathil sadly an error occured when I tried to trigger a build :( |
Is this intended to be in the |
doc/api/http.md
Outdated
@@ -648,6 +648,13 @@ stored without modification. Therefore, [`request.getHeader()`][] may return | |||
non-string values. However, the non-string values will be converted to strings | |||
for network transmission. | |||
|
|||
If [`response.writeHead()`][] method is called and this method has not been | |||
called, it will directly write the supplied header values onto the network channel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This long line seems to break linting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with @vsemozhetbyt's nit addressed.
2526761
to
f429d40
Compare
that is interesting. I ran
$ make lint-ci
any idea why? Nevertheless, made the changes and pushed, please have a look. |
No, it is meant at |
@gireeshpunathil The |
@gireeshpunathil Currently, the first fragment is placed in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be fixed up before it can land
doc/api/http.md
Outdated
@@ -648,6 +648,13 @@ stored without modification. Therefore, [`request.getHeader()`][] may return | |||
non-string values. However, the non-string values will be converted to strings | |||
for network transmission. | |||
|
|||
If [`response.writeHead()`][] method is called and this method has not been |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is inserted in an incorrect area or has the wrong links.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, ptal.
doc/api/http.md
Outdated
called, it will directly write the supplied header values onto the network | ||
channel without caching internally, and the [`response.getHeader()`][] on the | ||
header will not yield the expected result. If progressive population of headers | ||
are desired with potential future retrieval and modification, use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are desired -> is desired?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
doc/api/http.md
Outdated
If this method is called and [`response.setHeader()`][] has not been called, | ||
it will directly write the supplied header values onto the network channel | ||
without caching internally, and the [`response.getHeader()`][] on the header | ||
will not yield the expected result. If progressive population of headers are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are desired -> is desired?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks.
calling writeHead() into a Response object that has no headers already set causes getHeader() to return undefined, even if the header was set in the writeHead() function call. Explain this behavior as an optimiation as opposed to a bug. Fixes: nodejs#10354
749e155
to
c86df32
Compare
called, it will directly write the supplied header values onto the network | ||
channel without caching internally, and the [`response.getHeader()`][] on the | ||
header will not yield the expected result. If progressive population of headers | ||
is desired with potential future retrieval and modification, use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is modification still possible after writeHead
? Sounds to me like only retrieval is possible. Ditto below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimothyGu - yes, that is right: headers written through writeHead
are not modifiable, and attempt to do so results in error Cannot set headers after they are sent to the client
. Hence the suggestion to use setHeader()
API for such cases. If the text is not conveying that let me know where and how can I fix it, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you wrote
If progressive population of headers is desired with potential future retrieval and modification, use …
It seemed to me that the bolded bit should perhaps be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, missed this update. Sorry, I am missing your point:
#cat 10354.js
const h = require('http')
h.createServer((q, r) => {
r.setHeader('foo', 'bar')
r.setHeader('foo', 'new')
r.end()
}).listen(12000, () => {
const c = h.get('http://localhost:12000', (m) => {
console.log(m.headers)
})
})
#node 10354.js
{ foo: 'new',
date: 'Thu, 21 Jun 2018 14:42:33 GMT',
connection: 'close',
'content-length': '0' }
setHeader()
is indeed used for modification, and hence the text. Can you please clarify your point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind, I see what this is trying to say now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc format LGTM)
In the light of recent changes to the build process, what is the CI recommendation for doc changes? (sorry, I was not keeping track of the conversations) full CI (manual trigger) / lite CI (manual trigger) / do nothing - as the auto-CI said all checks have passed. |
answering my own question, I guess it is |
calling writeHead() into a Response object that has no headers already set causes getHeader() to return undefined, even if the header was set in the writeHead() function call. Explain this behavior as an optimiation as opposed to a bug. Fixes: #10354 PR-URL: #21289 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
landed as cbe307d |
calling writeHead() into a Response object that has no headers already set causes getHeader() to return undefined, even if the header was set in the writeHead() function call. Explain this behavior as an optimiation as opposed to a bug. Fixes: #10354 PR-URL: #21289 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
calling writeHead() into a Response object that has no headers already
set causes getHeader() to return undefined, even if the header was set
in the writeHead() function call. Explain this behavior as an
optimiation as opposed to a bug.
Fixes: #10354
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes