alexliesenfeld / health

A simple and flexible health check library for Go.
MIT License
779 stars 38 forks source link

In actual response content type is text/plain even for (default) http.JSONResultWriter #9

Closed panta closed 3 years ago

panta commented 3 years ago

This doesn't happen with unit tests, maybe there is a difference when using httptest? With a real handler I get the response with a text/plain Content-Type. I guess this is because the status is emitted before the Content-Type (ultimately set here).

alexliesenfeld commented 3 years ago

I understand. This is because WriteHeader is called before all headers are set (compare with https://github.com/golang/go/issues/17083).

alexliesenfeld commented 3 years ago

I think the ResultWriter needs to write the status code as well. Otherwise we will need to split the functionality into multiple functions or there will be ordering issues. The develop branch has a fix for this.