Skip to content

Conversation

@PoojaDurgad
Copy link
Contributor

@PoojaDurgadPoojaDurgad commented Nov 2, 2020

Make response.setHeader return the response object itself
so that multiple header setting can be chained.

Fixes: #33148

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

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/net

@nodejs-github-botnodejs-github-bot added the http Issues or PRs related to the http subsystem. label Nov 2, 2020
@mscdex
Copy link
Contributor

The targeted subsystem can just be http in the commit message instead of lib,http since http is the only thing being changed here.

@mscdexmscdex changed the title lib,http: enable setHeader for call chaininghttp: enable setHeader for call chainingNov 2, 2020
@lpinca
Copy link
Member

Can you please add a test?

Copy link
Member

@lpincalpinca left a comment

Choose a reason for hiding this comment

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

I'm fine with the test file as is but it could be simplified to something like

'use strict';require('../common');constassert=require('assert');const{ ServerResponse }=require('http');constresponse=newServerResponse({method: 'GET',httpVersionMajor: 1,httpVersionMinor: 1});assert.strictEqual(response.setHeader('foo','bar'),response);

or just a single assertion like the one above in an already existing test where response.setHeader() is used.

There is no need to start a server and chaining is a logical consequence of returning the same object.

@rickyesrickyes added the request-ci Add this label to start a Jenkins CI on a PR. label Nov 5, 2020
@github-actionsgithub-actionsbot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 5, 2020
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@TrottTrott added the semver-minor PRs that contain new features and should be released in the next minor version. label Nov 5, 2020
@Trott
Copy link
Member

Trott commented Nov 5, 2020

Nit on the commit message. Maybe this is a little more clear?: http: enable call chaining with setHeader() Or if you don't like that, maybe this?: http: enable setHeader() call chaining

@TrottTrott added the request-ci Add this label to start a Jenkins CI on a PR. label Nov 5, 2020
@github-actionsgithub-actionsbot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 5, 2020
@nodejs-github-bot
Copy link
Collaborator

@Trott
Copy link
Member

Trott commented Nov 5, 2020

Will this automatically add this for https as well? If so, should we add a test? If not, should we also add it to https?

@Trott
Copy link
Member

Trott commented Nov 5, 2020

@PoojaDurgad
Copy link
ContributorAuthor

Will this automatically add this for https as well? If so, should we add a test? If not, should we also add it to https?

@Trott - This behavior will be added to the https and need a test I guess . I think this feature can also be added to the http2 module too!!

@Trott
Copy link
Member

Trott commented Nov 6, 2020

Benchmark results show a small performance hit in some cases. Probably acceptable? @nodejs/http

07:04:12 confidence improvement accuracy (*) (**) (***) 07:04:12 http/set-header.js duration=5 res='normal' benchmarker='wrk' -2.36 % ±4.51% ±6.01% ±7.84% 07:04:12 http/set-header.js duration=5 res='setHeader' benchmarker='wrk' * -3.48 % ±3.17% ±4.22% ±5.49% 07:04:12 http/set-header.js duration=5 res='setHeaderWH' benchmarker='wrk' -2.83 % ±3.86% ±5.14% ±6.71% 07:04:12 http/set_header.js n=1000000 value='Connection' -2.96 % ±4.18% ±5.62% ±7.44% 07:04:12 http/set_header.js n=1000000 value='Content-Length' -0.92 % ±2.31% ±3.08% ±4.03% 07:04:12 http/set_header.js n=1000000 value='Content-Type' 0.05 % ±1.31% ±1.74% ±2.27% 07:04:12 http/set_header.js n=1000000 value='Set-Cookie' 0.75 % ±1.57% ±2.09% ±2.72% 07:04:12 http/set_header.js n=1000000 value='Transfer-Encoding' -0.75 % ±3.16% ±4.22% ±5.54% 07:04:12 http/set_header.js n=1000000 value='Vary' * -2.19 % ±1.95% ±2.61% ±3.41% 07:04:12 http/set_header.js n=1000000 value='X-Powered-By' 0.95 % ±1.86% ±2.48% ±3.23% 07:04:12 07:04:12 Be aware that when doing many comparisons the risk of a false-positive 07:04:12 result increases. In this case there are 10 comparisons, you can thus 07:04:12 expect the following amount of false-positive results: 07:04:12 0.50 false positives, when considering a 5% risk acceptance (*, **, ***), 07:04:12 0.10 false positives, when considering a 1% risk acceptance (**, ***), 07:04:12 0.01 false positives, when considering a 0.1% risk acceptance (***) 

@PoojaDurgad
Copy link
ContributorAuthor

is there anything pending on this PR? if yes let me know .

@TrottTrott added notable-change PRs with changes that should be highlighted in changelogs. and removed notable-change PRs with changes that should be highlighted in changelogs. labels Nov 28, 2020
@TrottTrott added the request-ci Add this label to start a Jenkins CI on a PR. label Nov 28, 2020
@github-actionsgithub-actionsbot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 28, 2020
@nodejs-github-bot
Copy link
Collaborator

@Trott
Copy link
Member

Landed in dedd061

@TrottTrott closed this Nov 30, 2020
@TrottTrott merged commit dedd061 into nodejs:masterNov 30, 2020
danielleadams pushed a commit that referenced this pull request Dec 7, 2020
Make `response.setHeader` return the response object itself so that multiple header setting can be chained. Fixes: #33148 PR-URL: #35924 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ricky Zhou <[email protected]> Reviewed-By: Rich Trott <[email protected]>
@danielleadamsdanielleadams mentioned this pull request Dec 7, 2020
danielleadams added a commit that referenced this pull request Dec 7, 2020
PR-URL: #36435 Notable changes: * child_processes: * add AbortSignal support (Benjamin Gruenbaum) (#36308) * deps: * update ICU to 68.1 (Michaël Zasso) (#36187) * events: * support signal in EventTarget (Benjamin Gruenbaum) (#36258) * graduate Event, EventTarget, AbortController (James M Snell) (#35949) * http: * enable call chaining with setHeader() (pooja d.p) (#35924) * module: * add isPreloading indicator (James M Snell) (#36263) * stream: * support abort signal (Benjamin Gruenbaum) (#36061) * add FileHandle support to Read/WriteStream (Momtchil Momtchev) (#35922) * worker: * add experimental BroadcastChannel (James M Snell) (#36271)
cjihrig pushed a commit to cjihrig/node that referenced this pull request Dec 8, 2020
Make `response.setHeader` return the response object itself so that multiple header setting can be chained. Fixes: nodejs#33148 PR-URL: nodejs#35924 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ricky Zhou <[email protected]> Reviewed-By: Rich Trott <[email protected]>
danielleadams added a commit that referenced this pull request Dec 9, 2020
PR-URL: #36435 Notable changes: * child_processes: * add AbortSignal support (Benjamin Gruenbaum) (#36308) * deps: * update ICU to 68.1 (Michaël Zasso) (#36187) * events: * support signal in EventTarget (Benjamin Gruenbaum) (#36258) * graduate Event, EventTarget, AbortController (James M Snell) (#35949) * http: * enable call chaining with setHeader() (pooja d.p) (#35924) * module: * add isPreloading indicator (James M Snell) (#36263) * stream: * support abort signal (Benjamin Gruenbaum) (#36061) * add FileHandle support to Read/WriteStream (Momtchil Momtchev) (#35922) * worker: * add experimental BroadcastChannel (James M Snell) (#36271)
danielleadams added a commit that referenced this pull request Dec 9, 2020
PR-URL: #36435 Notable changes: * child_processes: * add AbortSignal support (Benjamin Gruenbaum) (#36308) * deps: * update ICU to 68.1 (Michaël Zasso) (#36187) * events: * support signal in EventTarget (Benjamin Gruenbaum) (#36258) * graduate Event, EventTarget, AbortController (James M Snell) (#35949) * http: * enable call chaining with setHeader() (pooja d.p) (#35924) * module: * add isPreloading indicator (James M Snell) (#36263) * stream: * support abort signal (Benjamin Gruenbaum) (#36061) * add FileHandle support to Read/WriteStream (Momtchil Momtchev) (#35922) * worker: * add experimental BroadcastChannel (James M Snell) (#36271)
targos pushed a commit that referenced this pull request May 1, 2021
Make `response.setHeader` return the response object itself so that multiple header setting can be chained. Fixes: #33148 PR-URL: #35924 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ricky Zhou <[email protected]> Reviewed-By: Rich Trott <[email protected]>
@danielleadamsdanielleadams mentioned this pull request May 3, 2021
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

httpIssues or PRs related to the http subsystem.semver-minorPRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

respose.setHeader() should return response to allow chaining

6 participants

@PoojaDurgad@nodejs-github-bot@mscdex@lpinca@Trott@rickyes