mirror of
https://github.com/gin-gonic/gin.git
synced 2026-11-19 16:57:22 +08:00
Merge ea2343fade28bdbc56d9427fde603d432b21d921 into 0f09c3a9b4626d9fe9979cf4d0521d6ae32ab646
This commit is contained in:
commit
fcac0a77bb
@ -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)
|
||||
|
||||
|
||||
@ -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, "<map><foo>bar</foo></map>", 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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user