Test_Ctx_Body_With_Compression_Immutable() — fiber Function Reference
Architecture documentation for the Test_Ctx_Body_With_Compression_Immutable() function in ctx_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD 7a269fb3_912e_f70b_732f_a8f3c6edd6a6["Test_Ctx_Body_With_Compression_Immutable()"] 7b3d4933_5ae3_f84d_ff6d_0cb34e268026["ctx_test.go"] 7a269fb3_912e_f70b_732f_a8f3c6edd6a6 -->|defined in| 7b3d4933_5ae3_f84d_ff6d_0cb34e268026 style 7a269fb3_912e_f70b_732f_a8f3c6edd6a6 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
ctx_test.go lines 1150–1259
func Test_Ctx_Body_With_Compression_Immutable(t *testing.T) {
t.Parallel()
tests := []struct {
name string
contentEncoding string
body []byte
expectedBody []byte
}{
{
name: "gzip",
contentEncoding: "gzip",
body: []byte("john=doe"),
expectedBody: []byte("john=doe"),
},
{
name: "gzip twice",
contentEncoding: "gzip, gzip",
body: []byte("double"),
expectedBody: []byte("double"),
},
{
name: "unsupported_encoding",
contentEncoding: "undefined",
body: []byte("keeps_ORIGINAL"),
expectedBody: []byte("Unsupported Media Type"),
},
{
name: "compress_not_implemented",
contentEncoding: "compress",
body: []byte("foo"),
expectedBody: []byte("Not Implemented"),
},
{
name: "gzip then unsupported",
contentEncoding: "gzip, undefined",
body: []byte("Go, be gzipped"),
expectedBody: []byte("Unsupported Media Type"),
},
{
name: "invalid_deflate",
contentEncoding: "gzip,deflate",
body: []byte("I'm not correctly compressed"),
expectedBody: []byte(zlib.ErrHeader.Error()),
},
{
name: "identity",
contentEncoding: "identity",
body: []byte("bar"),
expectedBody: []byte("bar"),
},
}
for _, testObject := range tests {
tCase := testObject // Duplicate object to ensure it will be unique across all runs
t.Run(tCase.name, func(t *testing.T) {
t.Parallel()
app := New()
app.config.Immutable = true
c := app.AcquireCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck,forcetypeassert // not needed
c.Request().Header.Set("Content-Encoding", tCase.contentEncoding)
encs := strings.SplitSeq(tCase.contentEncoding, ",")
for enc := range encs {
enc = utils.TrimSpace(enc)
if strings.Contains(tCase.name, "invalid_deflate") && enc == StrDeflate {
continue
}
switch enc {
case "gzip":
var b bytes.Buffer
gz := gzip.NewWriter(&b)
_, err := gz.Write(tCase.body)
require.NoError(t, err)
require.NoError(t, gz.Flush())
require.NoError(t, gz.Close())
tCase.body = b.Bytes()
case StrDeflate:
var b bytes.Buffer
fl := zlib.NewWriter(&b)
_, err := fl.Write(tCase.body)
require.NoError(t, err)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_Ctx_Body_With_Compression_Immutable() do?
Test_Ctx_Body_With_Compression_Immutable() is a function in the fiber codebase, defined in ctx_test.go.
Where is Test_Ctx_Body_With_Compression_Immutable() defined?
Test_Ctx_Body_With_Compression_Immutable() is defined in ctx_test.go at line 1150.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free