Esempio n. 1
0
func Try(c *neo.Ctx, next neo.Next) {

	next()

	if c.HasErrors() {
		c.Res.Status = 500
		msg := ""
		for _, e := range c.Errors {
			msg += e.Error() + "\n"
		}
		c.Res.Text(fmt.Sprint(msg))
	}
}
Esempio n. 2
0
// Gzip returns a middleware which compresses HTTP response using gzip compression scheme.
func Gzip(c *neo.Ctx, next neo.Next) {
	scheme := "gzip"

	c.Res.Header().Set("Vary", "Accept-Encoding")
	// c.Res.Header().Set("Content-Encoding", "gzip")
	if strings.Contains(c.Res.Header().Get("Accept-Encoding"), scheme) {
		w := writerPool.Get().(*gzip.Writer)
		//replace the rep in ctx
		w.Reset(c.Res.Writer())
		defer func() {
			w.Close()
			writerPool.Put(w)
		}()
		gw := gzipWriter{Writer: w, ResponseWriter: c.Res.Writer()}
		c.Res.Header().Set("Content-Encoding", scheme)
		//need a set function for c.Res
		c.Response().SetWriter(gw)
	}
	next()
	return

}