(t *testing.T)
| 50 | } |
| 51 | |
| 52 | func 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 | |
| 78 | func TestETag(t *testing.T) { |
| 79 | // t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…