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
Remove Content-Type for empty responses #1249
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1249 +/- ##
=======================================
Coverage 67.54% 67.54%
=======================================
Files 28 28
Lines 7812 7812
=======================================
Hits 5277 5277
Misses 2048 2048
Partials 487 487
Continue to review full report at Codecov.
|
Just adding that golang/go#20784 was closed so the spurious |
Unfortunately, this change causes unexpected behavior when the content type is previously set by
The content type is deleted even if it is wanted. I do not agree that empty response should not carry Content-type header from go-openapi/runtime#64, at least in case of HEAD requests, because it is one of often function. |
Agree with @pheepi. I'm running in the issue now that the As far as I know, Should this change be reverted and the burden moved to the application developer to just not set the |
This is an attempt at fixing go-openapi/runtime#64.
Some clients trip over responses with empty bodies and
Content-Type: application/json
as they feed the body directly to a JSON parser. As a zero length string is not a valid JSON this causes a parse error.As a prominent client jQuery barfs on this intentionally since 1.9: https://jquery.com/upgrade-guide/1.9/#jquery-ajax-returning-a-json-result-of-an-empty-string :(
Note that at the moment this change will cause empty responses to have
Content-Type: text/plain
set because its what go's http server does by default: golang/go#20784.Hopefully this will change in later go versions.
Nonetheless this fixes pedantic clients as an empty string is valid
text/plain