Skip to content

Commit

Permalink
fix(context): YAML judgment logic in Negotiate (#3966)
Browse files Browse the repository at this point in the history
  • Loading branch information
RedCrazyGhost committed May 14, 2024
1 parent 36b0ded commit 4f339e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
MIMEPOSTForm = binding.MIMEPOSTForm
MIMEMultipartPOSTForm = binding.MIMEMultipartPOSTForm
MIMEYAML = binding.MIMEYAML
MIMEYAML2 = binding.MIMEYAML2
MIMETOML = binding.MIMETOML
)

Expand Down Expand Up @@ -1182,7 +1183,7 @@ func (c *Context) Negotiate(code int, config Negotiate) {
data := chooseData(config.XMLData, config.Data)
c.XML(code, data)

case binding.MIMEYAML:
case binding.MIMEYAML, binding.MIMEYAML2:
data := chooseData(config.YAMLData, config.Data)
c.YAML(code, data)

Expand Down
8 changes: 4 additions & 4 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ func TestContextNegotiationWithJSON(t *testing.T) {
c.Request, _ = http.NewRequest("POST", "", nil)

c.Negotiate(http.StatusOK, Negotiate{
Offered: []string{MIMEJSON, MIMEXML, MIMEYAML},
Offered: []string{MIMEJSON, MIMEXML, MIMEYAML, MIMEYAML2},
Data: H{"foo": "bar"},
})

Expand All @@ -1211,7 +1211,7 @@ func TestContextNegotiationWithXML(t *testing.T) {
c.Request, _ = http.NewRequest("POST", "", nil)

c.Negotiate(http.StatusOK, Negotiate{
Offered: []string{MIMEXML, MIMEJSON, MIMEYAML},
Offered: []string{MIMEXML, MIMEJSON, MIMEYAML, MIMEYAML2},
Data: H{"foo": "bar"},
})

Expand All @@ -1226,7 +1226,7 @@ func TestContextNegotiationWithYAML(t *testing.T) {
c.Request, _ = http.NewRequest("POST", "", nil)

c.Negotiate(http.StatusOK, Negotiate{
Offered: []string{MIMEYAML, MIMEXML, MIMEJSON, MIMETOML},
Offered: []string{MIMEYAML, MIMEXML, MIMEJSON, MIMETOML, MIMEYAML2},
Data: H{"foo": "bar"},
})

Expand All @@ -1241,7 +1241,7 @@ func TestContextNegotiationWithTOML(t *testing.T) {
c.Request, _ = http.NewRequest("POST", "", nil)

c.Negotiate(http.StatusOK, Negotiate{
Offered: []string{MIMETOML, MIMEXML, MIMEJSON, MIMEYAML},
Offered: []string{MIMETOML, MIMEXML, MIMEJSON, MIMEYAML, MIMEYAML2},
Data: H{"foo": "bar"},
})

Expand Down

0 comments on commit 4f339e6

Please sign in to comment.