-
-
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
removes code duplication at handling HEAD method #1400
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1400 +/- ##
=======================================
Coverage 99.36% 99.36%
=======================================
Files 4 4
Lines 474 474
Branches 124 125 +1
=======================================
Hits 471 471
Partials 3 3
Continue to review full report at Codecov.
|
Actually, I probably formulated bad the objective of this PR: I would like to remove body type checking and size calculation from |
lib/application.js
Outdated
if ('HEAD' === ctx.method) { | ||
if (!res.headersSent && !ctx.response.has('Content-Length')) { | ||
const { length } = ctx.response; | ||
if (Number.isInteger(length)) { ctx.length = length; } |
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.
I'd like to remove {}
in single line, others LGTM
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.
Btw, did the team discussed the introduction of Prettier on codebase to avoid code style reviews? I can make a PR for it 🙋🏻♂️
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.
I would prefer Koa eslint config to be updated if anything.
Handling of
HEAD
method sets content length for JSON body, repeating the measurement logic fromresponse.length
. This PR fixes that, removes code duplication and centralising response body length calculation atresponse.length
, also removing external dependency here.If #1399 will also be merge it will allow to remove
is-json
dependency completely.