mirror of
https://github.com/astaxie/beego.git
synced 2025-07-01 03:50:18 +00:00
fix #1669 write empty body panic error
This commit is contained in:
@ -65,6 +65,11 @@ func (tc *TestController) GetManyRouter() {
|
||||
tc.Ctx.WriteString(tc.Ctx.Input.Query(":id") + tc.Ctx.Input.Query(":page"))
|
||||
}
|
||||
|
||||
func (tc *TestController) GetEmptyBody() {
|
||||
var res []byte
|
||||
tc.Ctx.Output.Body(res)
|
||||
}
|
||||
|
||||
type ResStatus struct {
|
||||
Code int
|
||||
Msg string
|
||||
@ -239,6 +244,21 @@ func TestManyRoute(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test for issue #1669
|
||||
func TestEmptyResponse(t *testing.T) {
|
||||
|
||||
r, _ := http.NewRequest("GET", "/beego-empty.html", nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
handler := NewControllerRegister()
|
||||
handler.Add("/beego-empty.html", &TestController{}, "get:GetEmptyBody")
|
||||
handler.ServeHTTP(w, r)
|
||||
|
||||
if body := w.Body.String(); body != "" {
|
||||
t.Error("want empty body")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotFound(t *testing.T) {
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
Reference in New Issue
Block a user