diff options
author | Aliaksandr Valialkin <valyala@gmail.com> | 2016-01-04 14:56:49 +0200 |
---|---|---|
committer | Aliaksandr Valialkin <valyala@gmail.com> | 2016-01-04 14:56:49 +0200 |
commit | 69a05ffcafa7e2c2d54501450427759f9fa64546 (patch) | |
tree | bbf0b3e11f14fcb1cf3d1f9e619065bfc67fa3b7 /header_regression_test.go | |
parent | Added URI.LastPathSegment helper function (diff) | |
download | fasthttp-69a05ffcafa7e2c2d54501450427759f9fa64546.tar.gz fasthttp-69a05ffcafa7e2c2d54501450427759f9fa64546.tar.bz2 fasthttp-69a05ffcafa7e2c2d54501450427759f9fa64546.zip |
Issue #28: do not set default Content-Type for empty response
Diffstat (limited to 'header_regression_test.go')
-rw-r--r-- | header_regression_test.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/header_regression_test.go b/header_regression_test.go index f3c425f..69a5775 100644 --- a/header_regression_test.go +++ b/header_regression_test.go @@ -3,9 +3,43 @@ package fasthttp import ( "bufio" "bytes" + "fmt" + "strings" "testing" ) +func TestIssue28ResponseWithoutBodyNoContentType(t *testing.T) { + var r Response + + // Empty response without content-type + s := r.String() + if strings.Contains(s, "Content-Type") { + t.Fatalf("unexpected Content-Type found in response header with empty body: %q", s) + } + + // Explicitly set content-type + r.Header.SetContentType("foo/bar") + s = r.String() + if !strings.Contains(s, "Content-Type: foo/bar\r\n") { + t.Fatalf("missing explicitly set content-type for empty response: %q", s) + } + + // Non-empty response. + r.Reset() + r.SetBodyString("foobar") + s = r.String() + if !strings.Contains(s, fmt.Sprintf("Content-Type: %s\r\n", defaultContentType)) { + t.Fatalf("missing default content-type for non-empty response: %q", s) + } + + // Non-empty response with custom content-type. + r.Header.SetContentType("aaa/bbb") + s = r.String() + if !strings.Contains(s, "Content-Type: aaa/bbb\r\n") { + t.Fatalf("missing custom content-type: %q", s) + } +} + func TestIssue6RequestHeaderSetContentType(t *testing.T) { testIssue6RequestHeaderSetContentType(t, "GET") testIssue6RequestHeaderSetContentType(t, "POST") |