Exemple #1
0
func (c *Config) Read(ctx echo.Context) bool {
	ct := X.X(ctx)
	req := ctx.Request()
	if !c.HtmlCacheOn || req.Method() != `GET` {
		return false
	}
	p := strings.Trim(req.URL().Path(), `/`)
	if p == `` {
		p = `index`
	}
	s := strings.SplitN(p, `/`, 3)

	if c.htmlCacheRules == nil {
		c.htmlCacheRules = make(map[string]*Rule)
		for key, rule := range c.HtmlCacheRules {
			c.htmlCacheRules[key] = c.Rule(rule)
		}
	}

	var rule *Rule
	switch len(s) {
	case 2:
		k := s[0] + `:` + s[1]
		if v, ok := c.htmlCacheRules[k]; ok {
			rule = v
		} else if v, ok := c.htmlCacheRules[s[1]]; ok {
			rule = v
		} else {
			k = s[0] + `:`
			if v, ok := c.htmlCacheRules[k]; ok {
				rule = v
			}
		}
	case 1:
		k := s[0] + `:`
		if v, ok := c.htmlCacheRules[k]; ok {
			rule = v
		}
	}
	var saveFile string = c.SaveFileName(rule, ctx)
	if saveFile == "" {
		return false
	}
	if ct.Format != `` {
		saveFile += `.` + ct.Format
	}
	mtime, expired := c.Expired(rule, ctx, saveFile)
	if expired {
		ctx.Set(`webx:saveHtmlFile`, saveFile)
		return false
	}
	//_ = mtime
	//ctx.File(saveFile, ``, false)

	if !HttpCache(ctx, mtime, nil) {
		html, err := com.ReadFile(saveFile)
		if err != nil {
			ctx.Object().Echo().Logger().Error(err)
		}
		Output(html, ct)
	}

	ct.Exit = true
	return true
}
Exemple #2
0
func (j *JWT) Ignore(on bool, c echo.Context) {
	c.Set(`webx:ignoreJwt`, on)
}
Exemple #3
0
func (c *Xsrf) Ignore(on bool, ctx echo.Context) {
	ctx.Set(`webx:ignoreXsrf`, on)
}