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

lib: refactor ServerResponse.prototype.writeHead #32399

Closed

Conversation

himself65
Copy link
Member

fix #32395

make HTTP and HTTP2 the behavior the same.

example, allow response.writeHead(200, undefined, { ...headers }) when the second parameter is undefined passing

writeHead(statusCode, statusMessage, headers) {
const state = this[kState];
if (state.closed || this.stream.destroyed)
return this;
if (this[kStream].headersSent)
throw new ERR_HTTP2_HEADERS_SENT();
if (typeof statusMessage === 'string')
statusMessageWarn();
if (headers === undefined && typeof statusMessage === 'object')
headers = statusMessage;

btw, I renamed the name of parameters for better coding experience

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the http Issues or PRs related to the http subsystem. label Mar 21, 2020
@himself65 himself65 force-pushed the 20200321-refactor-writeHead branch 4 times, most recently from 137b347 to 70ca662 Compare March 21, 2020 05:10
@himself65 himself65 force-pushed the 20200321-refactor-writeHead branch from 70ca662 to 10962bc Compare March 24, 2020 02:28
@@ -150,7 +150,7 @@ const s = http.createServer(common.mustCall((req, res) => {
case 'writeHead':
res.statusCode = 404;
res.setHeader('x-foo', 'keyboard cat');
res.writeHead(200, { 'x-foo': 'bar', 'x-bar': 'baz' });
res.writeHead(200, undefined, { 'x-foo': 'bar', 'x-bar': 'baz' });
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also keep the test case for writeHead(status[, headers])?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I'm looking for a suitable test file to add this new case

Copy link
Member

@ronag ronag Jun 21, 2020

Choose a reason for hiding this comment

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

@himself65 ping, did you get any further with this?

Copy link
Member Author

Choose a reason for hiding this comment

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

oh no, I have forgot about this...

@BridgeAR BridgeAR force-pushed the master branch 2 times, most recently from 8ae28ff to 2935f72 Compare May 31, 2020 12:18
@himself65 himself65 requested a review from a team as a code owner August 10, 2020 16:07
@aduh95
Copy link
Contributor

aduh95 commented Nov 8, 2020

@himself65 This needs a rebase.

@aduh95 aduh95 added the stalled Issues and PRs that are stalled. label Nov 8, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2020

This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2021

Closing this because it has stalled. Feel free to reopen if this PR is still relevant, or to ping the collaborator who labelled it stalled if you have any questions.

@github-actions github-actions bot closed this Jan 9, 2021
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. stalled Issues and PRs that are stalled.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

response.writeHead() does not default statusMessage if it's undefined
7 participants