diff --git a/header.go b/header.go index f831f0f..d4e55b4 100644 --- a/header.go +++ b/header.go @@ -116,6 +116,9 @@ func (h *RequestHeader) SetByteRange(startPos, endPos int) { // StatusCode returns response status code. func (h *ResponseHeader) StatusCode() int { + if h.statusCode == 0 { + return StatusOK + } return h.statusCode } @@ -1386,9 +1389,6 @@ func (h *ResponseHeader) AppendBytes(dst []byte) []byte { if statusCode < 0 { statusCode = StatusOK } - if statusCode == 0 { - statusCode = StatusOK - } dst = append(dst, statusLine(statusCode)...) server := h.Server() diff --git a/header_test.go b/header_test.go index 50ac2a1..00869b4 100644 --- a/header_test.go +++ b/header_test.go @@ -10,6 +10,14 @@ import ( "testing" ) +func TestResponseHeaderDefaultStatusCode(t *testing.T) { + var h ResponseHeader + statusCode := h.StatusCode() + if statusCode != StatusOK { + t.Fatalf("unexpected status code: %d. Expecting %d", statusCode, StatusOK) + } +} + func TestResponseHeaderDelClientCookie(t *testing.T) { cookieName := "foobar"