Skip to content

Commit

Permalink
Merge pull request gin-gonic#993 from easonlin404/docs
Browse files Browse the repository at this point in the history
Add SecureJSON doc
  • Loading branch information
javierprovecho authored Jul 8, 2017
2 parents e389556 + bf9758c commit e8187dd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e8187dd

Please sign in to comment.