mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
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:
committed by
Erik Dubbelboer
parent
b97bc32543
commit
85217e0d5e
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user