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

removes code duplication at handling HEAD method #1400

Merged
merged 8 commits into from
Oct 15, 2019
Merged

removes code duplication at handling HEAD method #1400

merged 8 commits into from
Oct 15, 2019

Conversation

tinovyatkin
Copy link
Contributor

@tinovyatkin tinovyatkin commented Oct 14, 2019

Handling of HEAD method sets content length for JSON body, repeating the measurement logic from response.length. This PR fixes that, removes code duplication and centralising response body length calculation at response.length, also removing external dependency here.
If #1399 will also be merge it will allow to remove is-json dependency completely.

@codecov
Copy link

codecov bot commented Oct 14, 2019

Codecov Report

Merging #1400 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           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
Impacted Files Coverage Δ
lib/application.js 98.19% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4f96829...02ffd32. Read the comment docs.

@tinovyatkin tinovyatkin changed the title removes code duplication removes code duplication at handling HEAD method Oct 14, 2019
lib/application.js Outdated Show resolved Hide resolved
@tinovyatkin
Copy link
Contributor Author

tinovyatkin commented Oct 14, 2019

Actually, I probably formulated bad the objective of this PR: I would like to remove body type checking and size calculation from HEAD handling at Application and have it just at one place - at response.length getter.

if ('HEAD' === ctx.method) {
if (!res.headersSent && !ctx.response.has('Content-Length')) {
const { length } = ctx.response;
if (Number.isInteger(length)) { ctx.length = length; }
Copy link
Member

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

Copy link
Contributor Author

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 🙋🏻‍♂️

Copy link
Contributor

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.

@dead-horse dead-horse merged commit be7d334 into koajs:master Oct 15, 2019
@tinovyatkin tinovyatkin deleted the remove-code-duplication branch October 15, 2019 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants