-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
Text\plain content type for several responces with accept application\json header #375
Comments
Investigating, thanks for the report! |
Oh interesting. I was able to pinpoint what appears to be causing this. Basically when ever the option of |
Yeah it's because where we're calling |
Looking through this the only thing we can really do here is attempt to infer the return type for the response before we call |
Okay a bit of a proposal type ContextFlowable[B any] interface {
ContextWithBody[B]
// Serialize serializes the given data to the response.
Serialize(data any, code int) error
// SerializeError serializes the given error to the response.
SerializeError(err error)
} Our A plus with the interface above. This allows is to move setting the default statuscode in func (c echoContext[B]) Serialize(data any) error {
status := c.echoCtx.Response().Status
if status == 0 {
status = c.DefaultStatusCode <--- we don't need to so this anymore
}
if status == 0 {
status = http.StatusOK <---- we would still want to do this
}
c.echoCtx.JSON(status, data)
return nil
} On our server it's not possible to set the error code on the fly without it being an error, cause we don't actually provide a way setting an StatusCode much like gin/echo (they basically just set a I'll be putting up a PR showing the change soon. |
To Reproduce
I'm testing pet store api from examples
Expected behavior
I expect, that with header "Accept: application/json" response header "Content-Type" will be same as accept. But actually it's text/plain. Same with accept /, it return text/plain
Framework version (please check if it happens with the last
Fuego version before posting): v0.17.0
Go version (please check if it happens with the last Go version before posting): 1.23.3
Additional context
I try do another request
curl --location -v 'http://localhost:9999/pets/pet-1'
and got response with content type application\json. According with doc default content type is html or json if no accept header or same as accept header. Did I miss something?The text was updated successfully, but these errors were encountered: