예제 #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)
}
예제 #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)
}
예제 #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)
}