From ea2343fade28bdbc56d9427fde603d432b21d921 Mon Sep 17 00:00:00 2001 From: Dv2Corn <320380254+Dv2Corn@users.noreply.github.com> Date: Thu, 12 Nov 2026 13:53:03 +0000 Subject: [PATCH] fix(context): render XML in Negotiate when text/xml is offered --- context.go | 2 +- context_test.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/context.go b/context.go index 582d00f2..1a632d6e 100644 --- a/context.go +++ b/context.go @@ -1425,7 +1425,7 @@ func (c *Context) Negotiate(code int, config Negotiate) { data := chooseData(config.HTMLData, config.Data) c.HTML(code, config.HTMLName, data) - case binding.MIMEXML: + case binding.MIMEXML, binding.MIMEXML2: data := chooseData(config.XMLData, config.Data) c.XML(code, data) diff --git a/context_test.go b/context_test.go index b82e04d5..8a79961c 100644 --- a/context_test.go +++ b/context_test.go @@ -1844,6 +1844,23 @@ func TestContextNegotiationWithXML(t *testing.T) { assert.Equal(t, "application/xml; charset=utf-8", w.Header().Get("Content-Type")) } +func TestContextNegotiationWithXML2(t *testing.T) { + w := httptest.NewRecorder() + c, _ := CreateTestContext(w) + c.Request, _ = http.NewRequest(http.MethodGet, "/", nil) + c.Request.Header.Set("Accept", MIMEXML2) + + c.Negotiate(http.StatusOK, Negotiate{ + Offered: []string{MIMEJSON, MIMEXML2}, + Data: H{"foo": "bar"}, + }) + + assert.Equal(t, http.StatusOK, w.Code) + assert.Equal(t, "bar", w.Body.String()) + assert.Equal(t, "application/xml; charset=utf-8", w.Header().Get("Content-Type")) + assert.False(t, c.IsAborted()) +} + func TestContextNegotiationWithYAML(t *testing.T) { w := httptest.NewRecorder() c, _ := CreateTestContext(w)