Skip to content

context.Negotiate does not support application/yaml #3965

Closed
@bakito

Description

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions