SecureJSON

使用 SecureJSON 来防止 JSON 劫持。如果给定结构是数组值,则默认情况下会在响应正文中添加前缀 "while(1),"

func main() {
	r := gin.Default()

	// You can also use your own secure json prefix
	// r.SecureJsonPrefix(")]}',\n")

	r.GET("/someJSON", func(c *gin.Context) {
		names := []string{"lena", "austin", "foo"}

		// Will output  :   while(1);["lena","austin","foo"]
		c.SecureJSON(http.StatusOK, names)
	})

	// Listen and serve on 0.0.0.0:8080
	r.Run(":8080")
}
上次修改时间为 2024 年 5 月 10 日:Bump GitHub action workflows (#276) (4371021)