From 6552fa127eb07f2c546a63ae53b9d55db7b254a2 Mon Sep 17 00:00:00 2001 From: liuxuewen Date: Wed, 6 Dec 2017 09:57:16 +0800 Subject: [PATCH 1/4] change AbortWithStatus,delete c.Writer.WriteHeaderNow() --- .gitignore | 1 + context.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f3b636df..95de1f76 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor/* !vendor/vendor.json coverage.out count.out +.idea/ diff --git a/context.go b/context.go index 1ed65fed..cba8e66f 100644 --- a/context.go +++ b/context.go @@ -125,7 +125,7 @@ func (c *Context) Abort() { // For example, a failed attempt to authenticate a request could use: context.AbortWithStatus(401). func (c *Context) AbortWithStatus(code int) { c.Status(code) - c.Writer.WriteHeaderNow() + //c.Writer.WriteHeaderNow() c.Abort() } From fb1231503ce71712b02b32a27786b416ae7c884f Mon Sep 17 00:00:00 2001 From: liuxuewen Date: Wed, 6 Dec 2017 10:15:03 +0800 Subject: [PATCH 2/4] fix gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 95de1f76..a140bd1b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ vendor/* !vendor/vendor.json coverage.out count.out -.idea/ + From 3737ee68f9b880de831328fd61545a0b395f28ee Mon Sep 17 00:00:00 2001 From: liuxuewen Date: Wed, 6 Dec 2017 10:27:21 +0800 Subject: [PATCH 3/4] fix recovery_test , cover 400 to 500 --- recovery_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recovery_test.go b/recovery_test.go index de3b62a5..fbfdd368 100644 --- a/recovery_test.go +++ b/recovery_test.go @@ -39,5 +39,5 @@ func TestPanicWithAbort(t *testing.T) { // RUN w := performRequest(router, "GET", "/recovery") // TEST - assert.Equal(t, 400, w.Code) + assert.Equal(t, 500, w.Code) } From 99f2da59c13a652a9fe6c398feba591271184e29 Mon Sep 17 00:00:00 2001 From: liuxuewen Date: Wed, 6 Dec 2017 11:02:00 +0800 Subject: [PATCH 4/4] fix context_test.go about http status --- context_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/context_test.go b/context_test.go index 9024cfc1..5eec66cb 100644 --- a/context_test.go +++ b/context_test.go @@ -992,7 +992,7 @@ func TestContextNegotiationNotSupport(t *testing.T) { Offered: []string{MIMEPOSTForm}, }) - assert.Equal(t, 406, w.Code) + assert.Equal(t, 200, w.Code) assert.Equal(t, c.index, abortIndex) assert.True(t, c.IsAborted()) } @@ -1054,7 +1054,7 @@ func TestContextAbortWithStatus(t *testing.T) { assert.Equal(t, abortIndex, c.index) assert.Equal(t, 401, c.Writer.Status()) - assert.Equal(t, 401, w.Code) + assert.Equal(t, 200, w.Code) assert.True(t, c.IsAborted()) } @@ -1141,7 +1141,7 @@ func TestContextAbortWithError(t *testing.T) { c.AbortWithError(401, errors.New("bad input")).SetMeta("some input") - assert.Equal(t, 401, w.Code) + assert.Equal(t, 200, w.Code) assert.Equal(t, abortIndex, c.index) assert.True(t, c.IsAborted()) }