mirror of
				https://github.com/gin-gonic/gin.git
				synced 2025-11-04 09:12:12 +08:00 
			
		
		
		
	Add SecureJSON doc
This commit is contained in:
		
							parent
							
								
									e38955615a
								
							
						
					
					
						commit
						bf9758ca05
					
				
							
								
								
									
										23
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user