Skip to content

Commit

Permalink
Add SecureJSON doc
Browse files Browse the repository at this point in the history
  • Loading branch information
easonlin404 authored and Tony Yip committed Feb 20, 2018
1 parent 4305cd4 commit 14f7e90
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 @@ -518,6 +518,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 14f7e90

Please sign in to comment.