Home / Function/ Test_Ctx_SendFile_ContentType() — fiber Function Reference

Test_Ctx_SendFile_ContentType() — fiber Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

ctx_test.go lines 5229–5269

func Test_Ctx_SendFile_ContentType(t *testing.T) {
	t.Parallel()
	app := New()

	// 1) simple case
	c := app.AcquireCtx(&fasthttp.RequestCtx{})
	err := c.Res().SendFile("./.github/testdata/fs/img/fiber.png")
	// check expectation
	require.NoError(t, err)
	require.Equal(t, StatusOK, c.Response().StatusCode())
	require.Equal(t, "image/png", string(c.Response().Header.Peek(HeaderContentType)))
	app.ReleaseCtx(c)

	// 2) set by valid file extension, not file header
	// see: https://github.com/valyala/fasthttp/blob/d795f13985f16622a949ea9fc3459cf54dc78b3e/fs.go#L1638
	c = app.AcquireCtx(&fasthttp.RequestCtx{})
	err = c.SendFile("./.github/testdata/fs/img/fiberpng.jpeg")
	// check expectation
	require.NoError(t, err)
	require.Equal(t, StatusOK, c.Response().StatusCode())
	require.Equal(t, "image/jpeg", string(c.Response().Header.Peek(HeaderContentType)))
	app.ReleaseCtx(c)

	// 3) set by file header if extension is invalid
	c = app.AcquireCtx(&fasthttp.RequestCtx{})
	err = c.SendFile("./.github/testdata/fs/img/fiberpng.notvalidext")
	// check expectation
	require.NoError(t, err)
	require.Equal(t, StatusOK, c.Response().StatusCode())
	require.Equal(t, "image/png", string(c.Response().Header.Peek(HeaderContentType)))
	app.ReleaseCtx(c)

	// 4) set by file header if extension is missing
	c = app.AcquireCtx(&fasthttp.RequestCtx{})
	err = c.SendFile("./.github/testdata/fs/img/fiberpng")
	// check expectation
	require.NoError(t, err)
	require.Equal(t, StatusOK, c.Response().StatusCode())
	require.Equal(t, "image/png", string(c.Response().Header.Peek(HeaderContentType)))
	app.ReleaseCtx(c)
}

Domain

Subdomains

Defined In

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free