MCPcopy Index your code
hub / github.com/kataras/iris / TestCache304

Function TestCache304

cache/browser_test.go:52–76  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

50}
51
52func TestCache304(t *testing.T) {
53 // t.Parallel()
54 app := iris.New()
55
56 expiresEvery := 4 * time.Second
57 app.Get("/", cache.Cache304(expiresEvery), func(ctx iris.Context) {
58 ctx.WriteString("send")
59 })
60 // handlers
61 e := httptest.New(t, app)
62
63 // when 304, content type, content length and if ETagg is there are removed from the headers.
64 insideCacheTimef := time.Now().Add(-expiresEvery).UTC().Format(app.ConfigurationReadOnly().GetTimeFormat())
65 r := e.GET("/").WithHeader(context.IfModifiedSinceHeaderKey, insideCacheTimef).Expect().Status(httptest.StatusNotModified)
66 r.Headers().NotContainsKey(context.ContentTypeHeaderKey).NotContainsKey(context.ContentLengthHeaderKey).NotContainsKey("ETag")
67 r.Body().IsEqual("")
68
69 // continue to the handler itself.
70 cacheInvalidatedTimef := time.Now().Add(expiresEvery).UTC().Format(app.ConfigurationReadOnly().GetTimeFormat()) // after ~5seconds.
71 r = e.GET("/").WithHeader(context.LastModifiedHeaderKey, cacheInvalidatedTimef).Expect().Status(httptest.StatusOK)
72 r.Body().IsEqual("send")
73 // now without header, it should continue to the handler itself as well.
74 r = e.GET("/").Expect().Status(httptest.StatusOK)
75 r.Body().IsEqual("send")
76}
77
78func TestETag(t *testing.T) {
79 // t.Parallel()

Callers

nothing calls this directly

Calls 12

NewFunction · 0.92
NewMethod · 0.80
WriteStringMethod · 0.80
StatusMethod · 0.80
HeadersMethod · 0.80
GetMethod · 0.65
FormatMethod · 0.65
NowMethod · 0.65
GetTimeFormatMethod · 0.65
ConfigurationReadOnlyMethod · 0.65
BodyMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…