-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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 is forced to text/plain when context.Bind() fails #633
Comments
Since gin actually has a special error type for this, ErrorTypeBind, it would be better if you still add the error to the context.
|
Two Issues:
|
Thank you, will fix |
Is this still an issue the project maintainers would like to resolve? At my company we just moved a project away from Gin because of this issue (which was very surprising from a developer perspective). I don't have time within the next few days, but I could probably get a fix for this together. I presume this isn't being treated as a bug and we'll want to keep the current behavior unless headers or a response are explicitly set? |
I came across this problem also and google lead me here. Not sure if this is a hack or a work around but its possible just to do the binding yourself and dealing with the error manually.
It just skips a few helper methods mainly Unfortunately there is no other way to enforce the "Content-type" to be anything other than text as |
@tom-drake @kenny-house you can use new |
gin-gonic/gin#633 <- closed, but still an issue
If you call
context.Bind()
and it fails,context.AbortWithError()
gets called, which means headers get sent. Result: you can't send a non-text/plain
response later.Example
If you send invalid JSON in the request, you should still expect the response to have the header
Content-Type: application/json; charset=utf-8
, but instead it hasContent-Type: text/plain; charset=utf-8
.IMO
context.BindJSON()
should not callcontext.AbortWithError()
. Instead, the caller should have to handle sending their own error response. If you agree, I'll certainly be happy to write the PR.The text was updated successfully, but these errors were encountered: