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

HEAD requests are not accepted #72

Open
dsinni opened this issue Dec 12, 2019 · 3 comments
Open

HEAD requests are not accepted #72

dsinni opened this issue Dec 12, 2019 · 3 comments

Comments

@dsinni
Copy link

dsinni commented Dec 12, 2019

Hello,

Currently, it appears that this does not accept HEAD requests with the default configuration, which results in 404 errors for those requests.

Is there a way to allow this through configuration currently? If not, would it maybe be worthwhile to add support for HEAD requests as well since they're basically simplified GET requests for header info?

Hoping someone can point me in the right direction here.

Appreciate your time.

@bripkens
Copy link
Owner

Hey @dsinni,

could you describe the use case behind this for me? Preferably with an example app in a PR so that I understand why this needs to be done (and to test changes)?

@dsinni
Copy link
Author

dsinni commented Dec 13, 2019

Hi, @bripkens.

Thanks for the reply.

I'm currently using connect-history-api-fallback in conjunction with vue-router's history mode.

Not sure I'll be able to provide an app at the moment, but an example seems to be the use of socket.io which appears to use HEAD requests. I've also seen that other libraries check for the existence of paths/files using HEAD requests as they're lighter than GET since there is no response body.

AFAIK, express will accept HEAD requests through GET routes, if HEAD routes are not set explicitly, which seems like it would do the trick, but connect-history-api-fallback looks like it's rejecting these requests, resulting in 404s.

A simple test could be done by comparing GET with HEAD:

// GET: works as expected
fetch(url, { method: 'get' }).then(res => console.log(res));

// HEAD: results in 404 Not Found
fetch(url, { method: 'head' }).then(res => console.log(res));

These errors are more apparent in Google Chrome, but can also be seen in the Network tab in Firefox DevTools.

Since HEAD requests are very similar to GET in nature, and express handles them as GET for the most part, it seems it would make sense to make it an option to accept them, if not by default.

I'm not sure if this will provide additional context, but also may be worth a look: webpack/webpack-dev-server#924

I appreciate your attention to this, as it could really help out with the issues I'm facing.

dsinni added a commit to dsinni/connect-history-api-fallback that referenced this issue Dec 13, 2019
This proposal handles `HEAD` requests similarly to `GET` requests, since they are essentially the same with the different of `HEAD` response not containing a body.

If special handing for `HEAD` requests is needed, that can be set explicitly in `express` routing or otherwise.
@watery
Copy link

watery commented Nov 3, 2020

Hi @bripkens and @dsinni, any update on this?

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

No branches or pull requests

3 participants