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

fix(middleware): add HEAD method support #393

Closed
wants to merge 5 commits into from

Conversation

EslamHiko
Copy link
Member

What kind of change does this PR introduce?
bugfix

Did you add tests for your changes?
yes

Summary
fixes: webpack/webpack-dev-server#1833

Does this PR introduce a breaking change?
no

Other information
when I run tests I get lint errors :
Expected linebreaks to be 'LF' but found 'CRLF' and Delete '␍'
and when I disable lint and run tests only requests' tests fail in expecting Content-Length and Content-Range
I'm using windows and I tried this on Ubuntu and it's the same. so is it normal?

@codecov
Copy link

codecov bot commented May 11, 2019

Codecov Report

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

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #393   +/-   ##
=======================================
  Coverage   96.86%   96.86%           
=======================================
  Files          13       13           
  Lines         287      287           
  Branches       83       83           
=======================================
  Hits          278      278           
  Misses          9        9
Impacted Files Coverage Δ
lib/middleware.js 94.64% <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 6d191d0...b135c14. Read the comment docs.

@codecov
Copy link

codecov bot commented May 11, 2019

Codecov Report

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

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #393   +/-   ##
=======================================
  Coverage   96.86%   96.86%           
=======================================
  Files          13       13           
  Lines         287      287           
  Branches       83       82    -1     
=======================================
  Hits          278      278           
  Misses          9        9
Impacted Files Coverage Δ
lib/middleware.js 94.64% <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 762efe4...155e0ce. Read the comment docs.

@@ -44,7 +44,7 @@ module.exports = function wrapper(context) {
});
}

const acceptedMethods = context.options.methods || ['GET'];
const acceptedMethods = context.options.methods || ['GET', 'HEAD'];
Copy link
Member

Choose a reason for hiding this comment

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

What about support all method by defaults?

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Good job, one note

@alexander-akait
Copy link
Member

Let's wait CI green and release as new version

Honestly, I don’t know why before that we only allowed get 😕

@EslamHiko
Copy link
Member Author

@evilebottnawi I think because the most used method of requests is get so it was set to be the default. the problem was allowing get only.

@alexander-akait
Copy link
Member

/cc @hiroppy What do you think about supporting all method by default?

@@ -69,7 +69,7 @@ _Note: The `publicPath` property is required, whereas all other options are opti
### methods

Type: `Array`
Default: `[ 'GET' ]`
Default: `undefined`
Copy link
Member

Choose a reason for hiding this comment

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

I think this change seems to be breaking change. Is this wrong?

Copy link
Member Author

Choose a reason for hiding this comment

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

@hiroppy I don't think so here is the check :

const acceptedMethods = context.options.methods;

    if (acceptedMethods && acceptedMethods.indexOf(req.method) === -1) {
      return goNext();
    }

and in tests I changed the post request test that supposed to return 404 in the previous settings to be like get now it passes the test without issues.

I changed the documentation a little in the last commit, so now it makes more sense.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it is not breaking change, it is feature

@hiroppy
Copy link
Member

hiroppy commented May 13, 2019

Honestly, I don’t know why before that we only allowed get

Yeah, me too. So I think this change is good.

@alexander-akait
Copy link
Member

After investigate in other middleware code (one of popular exmaples https://github.com/expressjs/serve-static/blob/master/index.js#L73) i find what i was wrong, we should handle only GET and HEAD by default

@alexander-akait
Copy link
Member

I send a PR, sorry for this

@alexander-akait
Copy link
Member

Close in favor #398, sorry again for misleading

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.

Support HEAD request
3 participants