Former-commit-id: 6e0708f87f6ee9c6efd92f7677595feb8910988a
This commit is contained in:
Gerasimos (Makis) Maropoulos 2020-07-11 01:01:28 +03:00
parent 54bef51eb9
commit 3574816e1d
3 changed files with 924 additions and 912 deletions

View File

@ -9,19 +9,25 @@ import (
// Follow these steps first:
// $ go get -u github.com/kataras/bindata/cmd/bindata
// $ bindata ./assets/...
// $ go build
// $ go run .
// $ ./embedding-gziped-files-into-app
// "physical" files are not used, you can delete the "assets" folder and run the example.
func newApp() *iris.Application {
app := iris.New()
// 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.
// Note the `GzipAsset` and `GzipAssetNames` are different from go-bindata's `Asset`,
// 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{
Asset: GzipAsset,
AssetInfo: GzipAssetInfo,
AssetNames: GzipAssetNames,
AssetValidator: func(ctx iris.Context, name string) bool {
ctx.Header("Vary", "Accept-Encoding")
ctx.Header("Content-Encoding", "gzip")
return true
},
})
return app
}

View File

@ -85,7 +85,7 @@ func TestEmbeddingGzipFilesIntoApp(t *testing.T) {
response := e.GET(url).Expect()
response.ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset())
response.ContentEncoding("gzip")
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)
}