Home / Function/ Test_Ctx_Body_With_Compression() — fiber Function Reference

Test_Ctx_Body_With_Compression() — fiber Function Reference

Architecture documentation for the Test_Ctx_Body_With_Compression() function in ctx_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  16f027c9_65cc_e57d_cde9_f8e3a1b8019f["Test_Ctx_Body_With_Compression()"]
  7b3d4933_5ae3_f84d_ff6d_0cb34e268026["ctx_test.go"]
  16f027c9_65cc_e57d_cde9_f8e3a1b8019f -->|defined in| 7b3d4933_5ae3_f84d_ff6d_0cb34e268026
  style 16f027c9_65cc_e57d_cde9_f8e3a1b8019f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

ctx_test.go lines 917–1025

func Test_Ctx_Body_With_Compression(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()
			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)
					require.NoError(t, fl.Flush())

Domain

Subdomains

Defined In

Frequently Asked Questions

What does Test_Ctx_Body_With_Compression() do?
Test_Ctx_Body_With_Compression() is a function in the fiber codebase, defined in ctx_test.go.
Where is Test_Ctx_Body_With_Compression() defined?
Test_Ctx_Body_With_Compression() is defined in ctx_test.go at line 917.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free