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

  • go version: 1.22
  • gin version (or commit ref): 1.20.0
  • operating system: ubuntu

Comment From: RedCrazyGhost

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

Comment From: appleboy

@bakito Try the latest version.

Comment From: bakito

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