From bf9758ca05e47a74d55995ef62042a1c62cbb53c Mon Sep 17 00:00:00 2001 From: Eason Lin Date: Sun, 9 Jul 2017 01:54:43 +0800 Subject: [PATCH] Add SecureJSON doc --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index eda1dd7..cc97c7a 100644 --- a/README.md +++ b/README.md @@ -559,6 +559,29 @@ func main() { } ``` +#### SecureJSON + +Using SecureJSON to prevent json hijacking. Default prepends `"while(1),"` to response body if the given struct is array values. + +```go +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") +} +``` + ### Serving static files ```go