Ejemplo n.º 1
0
func (l *Logger) handle(ctx *rocket.Context) {
	l.start = time.Now()
	l.next(ctx)
	duration := time.Since(l.start) / time.Millisecond
	contentLenght := humanize.Bytes(uint64(ctx.GetContentLength()))
	log.Printf("%s %s %d %dms - %s", ctx.Request.Method, ctx.Request.RequestURI, ctx.GetStatusCode(), duration, contentLenght)
}
Ejemplo n.º 2
0
func (c *Cors) PreflightHandle(ctx *rocket.Context) {
	//ctx.Header().Add("Access-Control-Allow-Credentials", strconv.FormatBool(c.config.AllowCredentials))
	//ctx.Header().Add("Access-Control-Allow-Origin", c.config.AllowOrigin)
	//ctx.Header().Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
	//Access-Control-Allow-Methods
	ctx.Header().Add("Access-Control-Allow-Methods", strings.Join(c.config.AllowMethods, ", "))
	ctx.Header().Add("Access-Control-Allow-Headers", strings.Join(c.config.AllowHeaders, ", "))
	c.next(ctx)
}
Ejemplo n.º 3
0
func (c *Cors) SimpleHandle(ctx *rocket.Context) {
	ctx.Header().Add("Access-Control-Allow-Credentials", strconv.FormatBool(c.config.AllowCredentials))
	ctx.Header().Add("Access-Control-Allow-Origin", c.config.AllowOrigin)

	if c.config.AllowMethods != nil {
		ctx.Header().Add("Access-Control-Allow-Methods", strings.Join(c.config.AllowMethods, ", "))
	}

	if c.config.AllowHeaders != nil {
		ctx.Header().Add("Access-Control-Allow-Headers", strings.Join(c.config.AllowHeaders, ", "))
	}
	//Access-Control-Allow-Methods
	c.next(ctx)
}