uNetworking / uWebSockets

Simple, secure & standards compliant web server for the most demanding of applications
Apache License 2.0
17.24k stars 1.75k forks source link

Add option for redirecting head to get #1190

Closed hellow554 closed 3 years ago

hellow554 commented 3 years ago

According to wikipedia

The HEAD method asks for a response identical to that of a GET request, but without the response body. This is useful for retrieving meta-information written in response headers, without having to transport the entire content.

Currently they are two distinct listeners where I can each register a callback.

I would like to see that if no head callback is defined, but a get cb, that uwebsockets calls the get callback and throws away the body (:

Maybe this one can be used with an AppOption, e.g. redirectHeadToGet or similar if you don't like that to happen per default.

What do you think?

ghost commented 3 years ago

It's a good proposal but I think that falls out of scope.

You can easily wrap get and head functions into a convenience function taking bool isHead then making the appropriate decisions.

app.getOrHead with res, req, isHead

hellow554 commented 3 years ago

app.getOrHead

do you suggest a new method on the TemplatedApp class, or am I misreading it?

ghost commented 3 years ago

I could add getOrHead, but there is already head and get, so I don't see why I should provide mixes of components. That is not going to scale, scope-wise. You have to do with what you have.