| 1867 | } |
| 1868 | |
| 1869 | func 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 |