MCPcopy
hub / github.com/gofiber/fiber / Test_CacheStorage_CustomHeaders

Function Test_CacheStorage_CustomHeaders

middleware/cache/cache_test.go:1869–1894  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1867}
1868
1869func Test_CacheStorage_CustomHeaders(t *testing.T) {
1870 t.Parallel()
1871 app := fiber.New()
1872 app.Use(New(Config{
1873 Storage: memory.New(),
1874 MaxBytes: 10 * 1024 * 1024,
1875 }))
1876
1877 app.Get("/", func(c fiber.Ctx) error {
1878 c.Response().Header.Set("Content-Type", "text/xml")
1879 c.Response().Header.Set("Content-Encoding", "utf8")
1880 return c.Send([]byte("<xml><value>Test</value></xml>"))
1881 })
1882
1883 resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/", http.NoBody))
1884 require.NoError(t, err)
1885 body, err := io.ReadAll(resp.Body)
1886 require.NoError(t, err)
1887
1888 respCached, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/", http.NoBody))
1889 require.NoError(t, err)
1890 bodyCached, err := io.ReadAll(respCached.Body)
1891 require.NoError(t, err)
1892 require.True(t, bytes.Equal(body, bodyCached))
1893 require.NotEmpty(t, respCached.Header.Get(fiber.HeaderCacheControl))
1894}
1895
1896// Because time points are updated once every X milliseconds, entries in tests can often have
1897// equal expiration times and thus be in a random order. This closure hands out increasing

Callers

nothing calls this directly

Calls 9

NewFunction · 0.92
TestMethod · 0.80
NewFunction · 0.70
NewMethod · 0.65
UseMethod · 0.65
GetMethod · 0.65
SetMethod · 0.65
ResponseMethod · 0.65
SendMethod · 0.65

Tested by

no test coverage detected