Open nicklaw5 opened 5 years ago
:+1: thanks for the report @nicklaw5
It looks like the ResponseWriter.WriteHeader()
call flushes, disallowing any additional header setting.
My initial thought is to move that call into the default PanicFormatter
and require library users overriding the Formatter
to set their own response code. This would, however, make it more of a PanicHandler
than a PanicFormatter
so perhaps one solution is to introduce a new PanicHandler
field and deprecate the `PanicFormatter. This would also allow us to preserve compatibility.
I'll think about this a bit more, but suggestions welcome!
Your suggestion of introducing a PanicHandler
and deprecating the PanicFormatter
sounds good to me. If we could also preserve writing the default 500 Internal Server Error
response status, unless ResponseWriter.WriteHeader()
is called within PanicHandler
, that would also be ideal.
:+1: agreed; I think that should be feasible by passing in a different ResponseWriter
that would do something akin to https://github.com/urfave/negroni/blob/master/response_writer.go#L56-L64.
I'll try to get to this, but PRs also welcome :smile:
The docs indicate that when overriding the default
Recovery.Formatter
, it's possible to set response headers. I'm currently attempting to set theContent-Type
header toapplication/json
, however it appears that doesn't stick and reverts totext/plain; charset=utf-8
.Example: