go-siris / siris

DEPRECATED: The community driven fork of Iris. The fastest web framework for Golang!
Other
142 stars 16 forks source link

Enable gzip #25

Closed speedwheel closed 7 years ago

speedwheel commented 7 years ago

Hello,

I can't find anywhere in the documentation how to enable gzip, any thoughts?

Thanks

Allendar commented 7 years ago

Inside a request you can do c.Gzip(true) where c is context.Context.

If you want something global, you can use MiddleWare:

app := siris.New()
app.Use(func(c context.Context) {
    c.Gzip(true)

    c.Next()
})
speedwheel commented 7 years ago

That did the trick, thanks,

speedwheel commented 7 years ago

Actually now I noticed that I get many "net::ERR_CONTENT_LENGTH_MISMATCH" errors in my console log, and some of the resources are not displaying.

If I remove the gzip then everything comes back to normal.

Dexus commented 7 years ago

@speedwheel have you an example where we can look into it?

speedwheel commented 7 years ago

For example on this page: http://207.154.215.35:8080/5952048c1aa9514c81f9eeec check the console logs.

app.Use(func(c context.Context) {
    c.Gzip(true)
    c.Next()
})
app.AttachView(tmpl.Layout("layouts/default.html").Reload(true))
app.StaticWeb("/static", config.GetAppPath()+"resources")