mirror of
https://github.com/kataras/iris.git
synced 2025-02-13 04:26:18 +01:00
add doc for #1556
Former-commit-id: 6e0708f87f6ee9c6efd92f7677595feb8910988a
This commit is contained in:
parent
54bef51eb9
commit
3574816e1d
File diff suppressed because it is too large
Load Diff
|
@ -9,19 +9,25 @@ import (
|
||||||
// Follow these steps first:
|
// Follow these steps first:
|
||||||
// $ go get -u github.com/kataras/bindata/cmd/bindata
|
// $ go get -u github.com/kataras/bindata/cmd/bindata
|
||||||
// $ bindata ./assets/...
|
// $ bindata ./assets/...
|
||||||
// $ go build
|
// $ go run .
|
||||||
// $ ./embedding-gziped-files-into-app
|
// $ ./embedding-gziped-files-into-app
|
||||||
// "physical" files are not used, you can delete the "assets" folder and run the example.
|
// "physical" files are not used, you can delete the "assets" folder and run the example.
|
||||||
|
|
||||||
func newApp() *iris.Application {
|
func newApp() *iris.Application {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
|
|
||||||
// Note the `GzipAsset` and `GzipAssetNames` are different from `go-bindata`'s `Asset`,
|
// Note the `GzipAsset` and `GzipAssetNames` are different from go-bindata's `Asset`,
|
||||||
// do not set the `Gzip` option to true, it's already managed by the kataras/bindata.
|
// do not set the `Compress` option to true, instead
|
||||||
|
// use the `AssetValidator` option to manually set the content-encoding to "gzip".
|
||||||
app.HandleDir("/static", "./assets", iris.DirOptions{
|
app.HandleDir("/static", "./assets", iris.DirOptions{
|
||||||
Asset: GzipAsset,
|
Asset: GzipAsset,
|
||||||
AssetInfo: GzipAssetInfo,
|
AssetInfo: GzipAssetInfo,
|
||||||
AssetNames: GzipAssetNames,
|
AssetNames: GzipAssetNames,
|
||||||
|
AssetValidator: func(ctx iris.Context, name string) bool {
|
||||||
|
ctx.Header("Vary", "Accept-Encoding")
|
||||||
|
ctx.Header("Content-Encoding", "gzip")
|
||||||
|
return true
|
||||||
|
},
|
||||||
})
|
})
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ func TestEmbeddingGzipFilesIntoApp(t *testing.T) {
|
||||||
|
|
||||||
response := e.GET(url).Expect()
|
response := e.GET(url).Expect()
|
||||||
response.ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset())
|
response.ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset())
|
||||||
|
response.ContentEncoding("gzip")
|
||||||
if expected, got := response.Raw().StatusCode, httptest.StatusOK; expected != got {
|
if expected, got := response.Raw().StatusCode, httptest.StatusOK; expected != got {
|
||||||
t.Fatalf("[%d] of '%s': expected %d status code but got %d", i, url, expected, got)
|
t.Fatalf("[%d] of '%s': expected %d status code but got %d", i, url, expected, got)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user