decred / dcrtime

Decred anchored timestamp client, proxy, and server.
ISC License
28 stars 23 forks source link

Close the request body with a middleware instead of within the handler function body #85

Open tiagoalvesdulce opened 1 year ago

tiagoalvesdulce commented 1 year ago

As mentioned by Luke here: https://github.com/decred/dcrtime/pull/84#discussion_r1021757335.

We already have the middleware defined here: https://github.com/decred/dcrtime/blob/bbebe6df45a8c650c4e605d778494480b056f121/dcrtimed/dcrtimed.go#L1297

And are using it here: https://github.com/decred/dcrtime/blob/bbebe6df45a8c650c4e605d778494480b056f121/dcrtimed/dcrtimed.go#L1306

As we add every route with the addRoute method. It should be already working so the calls to defer r.Body.Close inside handler functions are redundant and can be removed.