diff --git a/header.go b/header.go index 3a552d9..7c9cc32 100644 --- a/header.go +++ b/header.go @@ -32,10 +32,10 @@ type ResponseHeader struct { noDefaultContentType bool noDefaultDate bool - statusCode int - contentLength int - contentLengthBytes []byte - secureErrorLogMessage bool + statusCode int + contentLength int + contentLengthBytes []byte + secureErrorLogMessage bool contentType []byte server []byte @@ -64,9 +64,9 @@ type RequestHeader struct { // for reducing RequestHeader object size. cookiesCollected bool - contentLength int - contentLengthBytes []byte - secureErrorLogMessage bool + contentLength int + contentLengthBytes []byte + secureErrorLogMessage bool method []byte requestURI []byte @@ -1649,7 +1649,7 @@ func (h *RequestHeader) AppendBytes(dst []byte) []byte { contentType := h.ContentType() if len(contentType) == 0 && !h.ignoreBody() { - contentType = strPostArgsContentType + contentType = strDefaultContentType } if len(contentType) > 0 { dst = appendHeaderLine(dst, strContentType, contentType) diff --git a/header_test.go b/header_test.go index e18c5cb..0f7c7f8 100644 --- a/header_test.go +++ b/header_test.go @@ -1250,6 +1250,33 @@ func TestResponseContentTypeNoDefaultNotEmpty(t *testing.T) { } } +func TestRequestContentTypeDefaultNotEmpty(t *testing.T) { + t.Parallel() + + var h RequestHeader + h.SetMethod(MethodPost) + h.SetContentLength(5) + + w := &bytes.Buffer{} + bw := bufio.NewWriter(w) + if err := h.Write(bw); err != nil { + t.Fatalf("Unexpected error: %s", err) + } + if err := bw.Flush(); err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + var h1 RequestHeader + br := bufio.NewReader(w) + if err := h1.Read(br); err != nil { + t.Fatalf("Unexpected error: %s", err) + } + + if string(h1.contentType) != "application/octet-stream" { + t.Fatalf("unexpected Content-Type %q. Expecting %q", h1.contentType, "application/octet-stream") + } +} + func TestResponseDateNoDefaultNotEmpty(t *testing.T) { t.Parallel() @@ -2416,7 +2443,6 @@ func TestResponseHeaderReadErrorSecureLog(t *testing.T) { testResponseHeaderReadSecuredError(t, h, "HTTP/1.1 123foobar OK\r\nContent-Length: 123\r\nContent-Type: text/html\r\n\r\n") testResponseHeaderReadSecuredError(t, h, "HTTP/1.1 foobar344 OK\r\nContent-Length: 123\r\nContent-Type: text/html\r\n\r\n") - // no headers testResponseHeaderReadSecuredError(t, h, "HTTP/1.1 200 OK\r\n") diff --git a/strings.go b/strings.go index e244f84..2a3d553 100644 --- a/strings.go +++ b/strings.go @@ -77,6 +77,7 @@ var ( strIdentity = []byte("identity") str100Continue = []byte("100-continue") strPostArgsContentType = []byte("application/x-www-form-urlencoded") + strDefaultContentType = []byte("application/octet-stream") strMultipartFormData = []byte("multipart/form-data") strBoundary = []byte("boundary") strBytes = []byte("bytes")