go-chi / chi

lightweight, idiomatic and composable router for building Go HTTP services
https://go-chi.io
MIT License
18.39k stars 983 forks source link

HEAD for GET routes #238

Closed alehano closed 7 years ago

alehano commented 7 years ago

Standard go http router allows to do HEAD requests to GET endpoints and return the same response but without body. Chi response 405 for GET routes with HEAD method.

DmitriyMV commented 7 years ago

Regarding Config - judging from the source code it's done automatically for new sub-routers as long as you use Route method. If you wish to explicitly mount the sub-router - you will have to initialize it correctly.

While Config approach is simpler, the middleware approach is more explicit and doesn't introduce this fix into the core of this router. That alone will allow us to use corrent "dirty" fix (documenting the fact, that headers will not be stripped from the resulting response) and introduce the proper one (once this https://github.com/golang/go/issues/4146 or https://github.com/golang/go/issues/16522 will be resolved) without breaking existing code.That and @VojtechVitek points about dynamic routing.

pkieltyka commented 7 years ago

yea, I think #248 is better too because it keeps the core lean and extends the api slightly to offer more power for people to program their own middlewares to change routing behaviour for their needs.

btw, @VojtechVitek - FindHandler requires the *Context because its actually doing routing through the tree, where it stores the url param values during traversal. Perhaps there is a better name than FindHandler, as what its doing is Routing the method and path to a handler. Maybe, Traverse(...) http.Handler or Seek(...) http.Handler or Match(...) http.Handler

DmitriyMV commented 7 years ago

@lwc @alehano @Vektah @c2h5oh any thoughts on the matter?

alehano commented 7 years ago

I agree with @VojtechVitek thoughts. I prefer #248 approach.

cardonator commented 7 years ago

248 is probably for the best. I think the concern above about starting to rely too much on Config is important. That probably best avoided for as long as possible.

pkieltyka commented 7 years ago

please review #248 again when you guys have a sec

pkieltyka commented 7 years ago

merged #248

DmitriyMV commented 7 years ago

Thanks! :+1: