mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 10:27:06 +00:00
Add one more browser (and 304 server) cache method using ETag and If-None-Match headers
And replace the 'ctx.WriteWithExpiration' with simple 'ctx.Write' at 'StaticEmbeddedHandler' of core/router/fs.go, now that we have plenty of options for client cache give the end-dev the oportunity to use them or not on static embedded handlers Former-commit-id: 9c9e2f3de3c5ad8c9e14e453b67e6b649b02bde8
This commit is contained in:
25
cache/browser_test.go
vendored
25
cache/browser_test.go
vendored
@@ -76,3 +76,28 @@ func TestCache304(t *testing.T) {
|
||||
r = e.GET("/").Expect().Status(httptest.StatusOK)
|
||||
r.Body().Equal("send")
|
||||
}
|
||||
func TestETag(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
app := iris.New()
|
||||
n := "_"
|
||||
app.Get("/", cache.ETag, func(ctx iris.Context) {
|
||||
ctx.WriteString(n)
|
||||
n += "_"
|
||||
})
|
||||
|
||||
// the first and last test writes the content with status OK without cache,
|
||||
// the rest tests the cache headers and status 304 and return, so body should be "".
|
||||
e := httptest.New(t, app)
|
||||
|
||||
r := e.GET("/").Expect().Status(httptest.StatusOK)
|
||||
r.Header("ETag").Equal("/") // test if header setted.
|
||||
r.Body().Equal("_")
|
||||
|
||||
e.GET("/").WithHeader("ETag", "/").WithHeader("If-None-Match", "/").Expect().
|
||||
Status(httptest.StatusNotModified).Body().Equal("") // browser is responsible, no the test engine.
|
||||
|
||||
r = e.GET("/").Expect().Status(httptest.StatusOK)
|
||||
r.Header("ETag").Equal("/") // test if header setted.
|
||||
r.Body().Equal("__")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user