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

Make automatic HEAD -> GET configurable #2247

Open
dougwilson opened this issue Jul 17, 2014 · 10 comments
Open

Make automatic HEAD -> GET configurable #2247

dougwilson opened this issue Jul 17, 2014 · 10 comments

Comments

@dougwilson
Copy link
Contributor

The automatic conversion of HEAD requests to GET requests when there is no HEAD method in the route should be configurable (i.e. turn it on or off).

@defunctzombie
Copy link
Contributor

Sounds like a router setting. 👍

@rsandor
Copy link

rsandor commented Mar 11, 2015

This behavior is not very clear (using 4.12.2). Take for example, registering routes in this order:

app.get('/resource/:id', getHandler);
app.head('/resource/:id', headHandler);

Done this way you will never ever hit the headHandler. However, if you reverse the order:

app.head('/resource/:id', headHandler);
app.get('/resource/:id', getHandler);

The headHandler is called on HTTP HEAD requests, and the getHandler is called on GET. Caused me a headache today 👎

@dougwilson
Copy link
Contributor Author

@rsandor yes, this is a sad situation :( This is one of the reasons we added .route() to Express 4.0, though, so you won't ever hit this issue:

app.route('/resource/:id')
.get(getHandler)
.head(headHandler)

@dougwilson
Copy link
Contributor Author

As a bonus, using .route() is more efficient, so you'll have a slightly higher throughput for the equivalent non-.route() app.

@Neta-Alon
Copy link

Sorry to bump an old issue - Is .route() always preferred, or just in situations where you have a single URL with a few HTTP methods?
Is it more efficient just in general?

@dougwilson
Copy link
Contributor Author

It is always preferred and more efficient in general, due to the stack being more compact.

@rsandor
Copy link

rsandor commented Jan 6, 2016

@dougwilson - Are the use of routes now enforced at an interface level in the newest versions of the library? If not, I highly suggest either making them so or simply fixing this issue. It seems like bad form to let a problem like this persist :/

@dougwilson
Copy link
Contributor Author

@rsandor , you're welcome to express your displeasure of the pace of this project to callback@strongloop.com , as this project is under StrongLoop and I am just a Collaborator.

@rsandor
Copy link

rsandor commented Jan 10, 2016

@dougwilson - kudos for not answering my question and taking the critique as a personal attack. Sorry I confused you with someone who could have an impact on the project.

@dougwilson
Copy link
Contributor Author

No problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants