mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 17:42:14 +08:00
remove context_17
This commit is contained in:
parent
c18fef0042
commit
3a5e3c013e
@ -1,17 +0,0 @@
|
|||||||
// Copyright 2018 Gin Core Team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a MIT style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build go1.7
|
|
||||||
|
|
||||||
package gin
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/gin-gonic/gin/render"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PureJSON serializes the given struct as JSON into the response body.
|
|
||||||
// PureJSON, unlike JSON, does not replace special html characters with their unicode entities.
|
|
||||||
func (c *Context) PureJSON(code int, obj interface{}) {
|
|
||||||
c.Render(code, render.PureJSON{Data: obj})
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
// Copyright 2018 Gin Core Team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a MIT style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build go1.7
|
|
||||||
|
|
||||||
package gin
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Tests that the response is serialized as JSON
|
|
||||||
// and Content-Type is set to application/json
|
|
||||||
// and special HTML characters are preserved
|
|
||||||
func TestContextRenderPureJSON(t *testing.T) {
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
c, _ := CreateTestContext(w)
|
|
||||||
c.PureJSON(http.StatusCreated, H{"foo": "bar", "html": "<b>"})
|
|
||||||
assert.Equal(t, http.StatusCreated, w.Code)
|
|
||||||
assert.Equal(t, "{\"foo\":\"bar\",\"html\":\"<b>\"}\n", w.Body.String())
|
|
||||||
assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user