return json if jsonp has not callback (#1438)

return json if jsonp has not callback
This commit is contained in:
solos
2018-07-21 00:52:55 +08:00
committed by Bo-Yi Wu
parent 85221af84c
commit 220e8d3453
2 changed files with 20 additions and 1 deletions

View File

@ -596,6 +596,20 @@ func TestContextRenderJSONP(t *testing.T) {
assert.Equal(t, "application/javascript; charset=utf-8", w.HeaderMap.Get("Content-Type"))
}
// Tests that the response is serialized as JSONP
// and Content-Type is set to application/json
func TestContextRenderJSONPWithoutCallback(t *testing.T) {
w := httptest.NewRecorder()
c, _ := CreateTestContext(w)
c.Request, _ = http.NewRequest("GET", "http://example.com", nil)
c.JSONP(201, H{"foo": "bar"})
assert.Equal(t, 201, w.Code)
assert.Equal(t, "{\"foo\":\"bar\"}", w.Body.String())
assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type"))
}
// Tests that no JSON is rendered if code is 204
func TestContextRenderNoContentJSON(t *testing.T) {
w := httptest.NewRecorder()