Correctly handle NoDefaultContentType without setting an Content-Type value (#628)

If `NoDefaultContentType` is set, but no actual `Content-Type` header is set, do not send the wrong `Content-Type: ` header
This commit is contained in:
Ciprian Dorin Craciun
2019-08-13 12:53:03 +03:00
committed by Erik Dubbelboer
parent b97bc32543
commit 85217e0d5e
2 changed files with 17 additions and 1 deletions
+4 -1
View File
@@ -1499,7 +1499,10 @@ func (h *ResponseHeader) AppendBytes(dst []byte) []byte {
// or if it is explicitly set.
// See https://github.com/valyala/fasthttp/issues/28 .
if h.ContentLength() != 0 || len(h.contentType) > 0 {
dst = appendHeaderLine(dst, strContentType, h.ContentType())
contentType := h.ContentType()
if len(contentType) > 0 {
dst = appendHeaderLine(dst, strContentType, contentType)
}
}
if len(h.contentLengthBytes) > 0 {
+13
View File
@@ -1111,6 +1111,19 @@ func TestRequestHeaderCopyTo(t *testing.T) {
}
}
func TestResponseContentTypeNoDefaultNotEmpty(t *testing.T) {
var h ResponseHeader
h.noDefaultContentType = true
h.SetContentLength(5)
headers := h.String()
if strings.Index(headers, "Content-Type: \r\n") != -1 {
t.Fatalf("ResponseContentTypeNoDefaultNotEmpty fail, response: \n%+v\noutcome: \n%q\n", h, headers)
}
}
func TestRequestHeaderConnectionClose(t *testing.T) {
var h RequestHeader