-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
ctx.response.get - use .getHeader #1392
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1392 +/- ##
==========================================
- Coverage 99.60% 99.37% -0.24%
==========================================
Files 5 4 -1
Lines 507 479 -28
Branches 143 127 -16
==========================================
- Hits 505 476 -29
+ Misses 2 0 -2
- Partials 0 3 +3
Continue to review full report at Codecov.
|
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
Note though, defaulting to string could be a behaviour that is relied on. I'd consider this a breaking change.
it is related with #1394 Because we change all headers to string when set, so get header default to empty string is reasonable. I'm -0 on both change even in the next major version, the current implementation is also reasonable, the new implementation does not have much benefit but introduces some incompatible changes. |
@dead-horse new implementation do have benefits, indeed:
ctx.res.setHeader('foo', 5);
ctx.response.get('foo') === 5; // true
ctx.response.set('foo', 5);
ctx.res.getHeader('foo') === 5; // false
|
More with current implementation: ctx.set('Content-Length', 10);
ctx.response.header['content-length'] = 0; // or ctx.res.setHeader('Content-Length', 0)
ctx.response.get('Content-Length); // => '' |
FYI, I think it's better to rebase the branch rather than to merge in changes (though if you rebase and squash the result will be equivalent). Just to omit some commit bloat I tend to stay clear from merge-commits if possible or squash. Others might disagree. |
@fl0w that's the GitHub suggested way to |
@tinovyatkin koa team seems don't like merge, can we together fork koa and fix many problem? i think you are right. |
response.header
fails back to standard methodresponse.getHeaders
on Node >= 7.7 (i.e. on all live Node versions today), so, it overkill to to get all headers first, then dofield.toLowercase
(specially without typechecking offield
).response.getHeader is a standard method since Node 0.x and it's doing all lowercasing internally.
Additionally, coercing to empty string is invalid here, as headers may contain non-string values before being sent to network, for example, Content-Length may be a number value of 0.