Write header immediately in AbortWithStatus()
Otherwise, caller needs to invoke WriteHeaderNow himself after AbortWithStatus(), which is error-prone. Also modified ErrorLoggerT() such that it always writes log to response body. Otherwise calling AbortWithStatus() will fail to write body because c.Writer.Written() is set true by WriteHeaderNow().
This commit is contained in:
@ -545,7 +545,6 @@ func TestContextAbortWithStatus(t *testing.T) {
|
||||
c, w, _ := CreateTestContext()
|
||||
c.index = 4
|
||||
c.AbortWithStatus(401)
|
||||
c.Writer.WriteHeaderNow()
|
||||
|
||||
assert.Equal(t, c.index, abortIndex)
|
||||
assert.Equal(t, c.Writer.Status(), 401)
|
||||
@ -596,7 +595,6 @@ func TestContextTypedError(t *testing.T) {
|
||||
func TestContextAbortWithError(t *testing.T) {
|
||||
c, w, _ := CreateTestContext()
|
||||
c.AbortWithError(401, errors.New("bad input")).SetMeta("some input")
|
||||
c.Writer.WriteHeaderNow()
|
||||
|
||||
assert.Equal(t, w.Code, 401)
|
||||
assert.Equal(t, c.index, abortIndex)
|
||||
|
Reference in New Issue
Block a user