Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content-Type header set for empty responses. #64

Closed
databus23 opened this issue Sep 15, 2017 · 0 comments
Closed

Content-Type header set for empty responses. #64

databus23 opened this issue Sep 15, 2017 · 0 comments

Comments

@databus23
Copy link

databus23 commented Sep 15, 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 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.

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 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant