diff --git a/header.go b/header.go index 3917f5c0de..59d0165b39 100644 --- a/header.go +++ b/header.go @@ -601,10 +601,15 @@ func (h *ResponseHeader) DisableNormalizing() { h.disableNormalizing = true } +// SetNoDefaultContentType allows you to control if a default Content-Type header will be set (false) or not (true). +func (h *ResponseHeader) SetNoDefaultContentType(noDefaultContentType bool) { + h.noDefaultContentType = noDefaultContentType +} + // Reset clears response header. func (h *ResponseHeader) Reset() { h.disableNormalizing = false - h.noDefaultContentType = false + h.SetNoDefaultContentType(false) h.noDefaultDate = false h.resetSkipNormalize() } diff --git a/header_test.go b/header_test.go index 2ef275094d..0fcca30806 100644 --- a/header_test.go +++ b/header_test.go @@ -1240,7 +1240,7 @@ func TestResponseContentTypeNoDefaultNotEmpty(t *testing.T) { var h ResponseHeader - h.noDefaultContentType = true + h.SetNoDefaultContentType(true) h.SetContentLength(5) headers := h.String() @@ -2193,10 +2193,10 @@ func TestResponseHeaderReadSuccess(t *testing.T) { 400, 123, string(defaultContentType), "foiaaa") // no content-type and no default - h.noDefaultContentType = true + h.SetNoDefaultContentType(true) testResponseHeaderReadSuccess(t, h, "HTTP/1.1 400 OK\r\nContent-Length: 123\r\n\r\nfoiaaa", 400, 123, "", "foiaaa") - h.noDefaultContentType = false + h.SetNoDefaultContentType(false) // no headers testResponseHeaderReadSuccess(t, h, "HTTP/1.1 200 OK\r\n\r\naaaabbb",