You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've bumped into a minor problem with a go-swagger generated apiserver when it comes to empty responses (e.g. DELETE requests). The problem is that a Content-Type: application/json response header is always set even for empty responses.
This is a problem at least for the jquery ajax client with tries to parse the empty body as json and fails.
In general I think its not really useful to set a Content-Type if the response body is empty.
I tried to come up with a simple fix for this but realised that this seems to be a bit more work and probably requires an api change because right now its not possible for the Context.Respond method to know if the given middleware.Responder will write some payload to the http.ResponseWriter. It would somehow need to know this in advance to decide if the Content-Type header should be set or not.
I'm willing to work on a PR but wanted to illicit some feedback if and how to proceed on this.
The text was updated successfully, but these errors were encountered:
databus23
added a commit
to databus23/go-swagger
that referenced
this issue
Nov 6, 2017
I've bumped into a minor problem with a
go-swagger
generated apiserver when it comes to empty responses (e.g. DELETE requests). The problem is that aContent-Type: application/json
response header is always set even for empty responses.This is a problem at least for the jquery ajax client with tries to parse the empty body as json and fails.
Here a related issue on stack overflow I found:
simphony/simphony-remote#184
golang/go#20784
Searching a bit it seems to me its not clearly defined if a Content-Type for an empty response is valid or not but it seems questionable at least:
https://stackoverflow.com/questions/40614416/is-empty-body-correct-if-content-type-is-application-json
https://stackoverflow.com/questions/15032932/what-should-the-content-type-be-for-a-4xx-error-without-a-body
In general I think its not really useful to set a Content-Type if the response body is empty.
I tried to come up with a simple fix for this but realised that this seems to be a bit more work and probably requires an api change because right now its not possible for the
Context.Respond
method to know if the givenmiddleware.Responder
will write some payload to thehttp.ResponseWriter
. It would somehow need to know this in advance to decide if theContent-Type
header should be set or not.I'm willing to work on a PR but wanted to illicit some feedback if and how to proceed on this.
The text was updated successfully, but these errors were encountered: