Test_CacheStaleResponseAddsWarning110() — fiber Function Reference
Architecture documentation for the Test_CacheStaleResponseAddsWarning110() function in cache_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD 65747e46_cb15_315f_b4f8_396e1a85c43b["Test_CacheStaleResponseAddsWarning110()"] 8453a087_9678_fe96_1b20_2d125b6f8656["cache_test.go"] 65747e46_cb15_315f_b4f8_396e1a85c43b -->|defined in| 8453a087_9678_fe96_1b20_2d125b6f8656 style 65747e46_cb15_315f_b4f8_396e1a85c43b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
middleware/cache/cache_test.go lines 2316–2371
func Test_CacheStaleResponseAddsWarning110(t *testing.T) {
t.Parallel()
app := fiber.New()
app.Use(New(Config{
Expiration: 2 * time.Second,
}))
var count int
app.Get("/", func(c fiber.Ctx) error {
count++
c.Set(fiber.HeaderCacheControl, "public, max-age=1")
return c.SendString("body" + strconv.Itoa(count))
})
resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/", http.NoBody))
require.NoError(t, err)
require.Equal(t, cacheMiss, resp.Header.Get("X-Cache"))
req := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
req.Header.Set(fiber.HeaderCacheControl, "max-stale=5")
// Wait for the cached response to become stale (max-age=1)
// Add extra time to ensure the entry has expired
time.Sleep(1200 * time.Millisecond)
deadline := time.Now().Add(3 * time.Second)
for {
resp, err = app.Test(req)
require.NoError(t, err)
if resp.Header.Get("X-Cache") == cacheHit {
ageVal, err := strconv.Atoi(resp.Header.Get(fiber.HeaderAge))
require.NoError(t, err)
if ageVal >= 1 {
// Check that Warning header is present before breaking
warnings := resp.Header.Values(fiber.HeaderWarning)
if len(warnings) > 0 {
break
}
}
}
require.True(t, time.Now().Before(deadline), "response did not become stale before deadline")
time.Sleep(50 * time.Millisecond)
}
warnings := resp.Header.Values(fiber.HeaderWarning)
require.NotEmpty(t, warnings, "Warning header should be present when serving stale response")
found := false
for _, w := range warnings {
if strings.Contains(w, "110") {
found = true
break
}
}
require.True(t, found, "warning 110 not found in %v", warnings)
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_CacheStaleResponseAddsWarning110() do?
Test_CacheStaleResponseAddsWarning110() is a function in the fiber codebase, defined in middleware/cache/cache_test.go.
Where is Test_CacheStaleResponseAddsWarning110() defined?
Test_CacheStaleResponseAddsWarning110() is defined in middleware/cache/cache_test.go at line 2316.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free