mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
Add option for Gzip again, I removed it after v3 but seems users wants it back
This commit is contained in:
parent
084b689d37
commit
6f91e6c588
|
@ -25,8 +25,8 @@ A **Response Engine** gives you the freedom to create/change the render/response
|
|||
**Small changes**
|
||||
|
||||
- `iris.Config.Charset`, before alpha.3 was `iris.Config.Rest.Charset` & `iris.Config.Render.Template.Charset`, but you can override it at runtime by passinth a map `iris.RenderOptions` on the `context.Render` call .
|
||||
- `iris.Config.IsDevelopment` , before alpha.1 was `iris.Config.Render.Template.IsDevelopment`
|
||||
|
||||
- `iris.Config.IsDevelopment`, before alpha.1 was `iris.Config.Render.Template.IsDevelopment`
|
||||
- `iris.Config.Gzip`, enables gzip compression on your Render actions, this includes any type of render, templates and pure/raw content. If you don't want to enable it globaly, you could just use the third parameter on context.Render("myfileOrResponse", structBinding{}, iris.RenderOptions{"gzip": true}). It defaults to false
|
||||
|
||||
**Websockets changes**
|
||||
|
||||
|
|
|
@ -94,6 +94,11 @@ type (
|
|||
// defaults to "UTF-8"
|
||||
Charset string
|
||||
|
||||
// Gzip enables gzip compression on your Render actions, this includes any type of render, templates and pure/raw content
|
||||
// If you don't want to enable it globaly, you could just use the third parameter on context.Render("myfileOrResponse", structBinding{}, iris.RenderOptions{"gzip": true})
|
||||
// defaults to false
|
||||
Gzip bool
|
||||
|
||||
// Sessions contains the configs for sessions
|
||||
Sessions Sessions
|
||||
|
||||
|
@ -114,6 +119,7 @@ func Default() Iris {
|
|||
DisableTemplateEngines: false,
|
||||
IsDevelopment: false,
|
||||
Charset: DefaultCharset,
|
||||
Gzip: false,
|
||||
ProfilePath: "",
|
||||
Sessions: DefaultSessions(),
|
||||
Websocket: DefaultWebsocket(),
|
||||
|
|
|
@ -135,10 +135,10 @@ func (r *responseEngineMap) render(ctx *Context, obj interface{}, options ...map
|
|||
finalResult = append(finalResult, result...)
|
||||
}
|
||||
|
||||
gzipEnabled := false
|
||||
gzipEnabled := ctx.framework.Config.Gzip
|
||||
charset := ctx.framework.Config.Charset
|
||||
if len(options) > 0 {
|
||||
gzipEnabled = getGzipOption(options[0]) // located to the template.go below the RenderOptions
|
||||
gzipEnabled = getGzipOption(ctx, options[0]) // located to the template.go below the RenderOptions
|
||||
if chs := getCharsetOption(options[0]); chs != "" {
|
||||
charset = chs
|
||||
}
|
||||
|
|
|
@ -71,12 +71,12 @@ func (t TemplateFuncs) IsFree(key string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func getGzipOption(options map[string]interface{}) bool {
|
||||
func getGzipOption(ctx *Context, options map[string]interface{}) bool {
|
||||
gzipOpt := options["gzip"] // we only need that, so don't create new map to keep the options.
|
||||
if b, isBool := gzipOpt.(bool); isBool {
|
||||
return b
|
||||
}
|
||||
return false
|
||||
return ctx.framework.Config.Gzip
|
||||
}
|
||||
|
||||
func getCharsetOption(options map[string]interface{}) string {
|
||||
|
@ -166,10 +166,11 @@ func (t *templateEngineWrapper) execute(ctx *Context, filename string, binding i
|
|||
}
|
||||
|
||||
// we do all these because we don't want to initialize a new map for each execution...
|
||||
gzipEnabled := false
|
||||
gzipEnabled := ctx.framework.Config.Gzip
|
||||
charset := ctx.framework.Config.Charset
|
||||
if len(options) > 0 {
|
||||
gzipEnabled = getGzipOption(options[0])
|
||||
gzipEnabled = getGzipOption(ctx, options[0])
|
||||
|
||||
if chs := getCharsetOption(options[0]); chs != "" {
|
||||
charset = chs
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user