Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(writer): panic occurred while processing redirect request #37

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ func (w *Writer) Write(data []byte) (int, error) {
// If the response writer has already written headers or if a timeout has occurred,
// this method does nothing.
func (w *Writer) WriteHeader(code int) {
checkWriteHeaderCode(code)
if w.timeout || w.wroteHeaders {
return
}

// gin is using -1 to skip writing the status code
// see https://github.com/gin-gonic/gin/blob/a0acf1df2814fcd828cb2d7128f2f4e2136d3fac/response_writer.go#L61
if code == -1 {
return
}

checkWriteHeaderCode(code)

w.mu.Lock()
defer w.mu.Unlock()

Expand Down
10 changes: 10 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ func TestWriteHeader(t *testing.T) {
})
}

func TestWriteHeader_SkipMinusOne(t *testing.T) {
code := -1

writer := Writer{}
assert.NotPanics(t, func() {
writer.WriteHeader(code)
assert.False(t, writer.wroteHeaders)
})
}

func TestWriter_Status(t *testing.T) {
r := gin.New()

Expand Down
Loading