gin-gonic / gin

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
https://gin-gonic.com/
MIT License
77.99k stars 7.97k forks source link

context.Negotiate does not support application/yaml #3965

Closed bakito closed 4 months ago

bakito commented 4 months ago

Description

with 1.10.0 support for application/yaml was introduced (#3851)

The Negotiate func of context (https://github.com/gin-gonic/gin/blob/master/context.go#L1179) does not support this content type yet.

How to reproduce

package main

import (
    "github.com/gin-gonic/gin"
)

func main() {
    g := gin.Default()
    g.GET("/hello/:name", func(c *gin.Context) {
            c.Negotiate(http.StatusInternalServerError, gin.Negotiate{
            Offered: []string{binding.MIMEJSON, binding.MIMEYAML2},
            Data:    gin.H{"error": err.Error()},
        })
    })
    g.Run(":9000")
}

Expectations

$ curl -H  "Content-Type: application/yaml" http://localhost:9000/hello/world
# should return status code 500 

Actual result

$ curl -H  "Content-Type: application/yaml" http://localhost:9000/hello/world
# status code 406

Environment

RedCrazyGhost commented 4 months ago

Hello, I submitted support for application/yaml judgment logic in Negotiate

appleboy commented 4 months ago

@bakito Try the latest version.

bakito commented 4 months ago

@appleboy I can conform, that my use case is working again when running against the master branch. @RedCrazyGhost Thank you very much