Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
51f0ef8b07 | ||
![]() |
88488351b0 | ||
![]() |
567de19169 | ||
![]() |
e641d4ab82 | ||
![]() |
1238974274 | ||
![]() |
f894742c19 | ||
![]() |
796e03648c | ||
![]() |
5c9b3fa52c |
@ -5,6 +5,7 @@ go:
|
|||||||
- 1.6.x
|
- 1.6.x
|
||||||
- 1.7.x
|
- 1.7.x
|
||||||
- 1.8.x
|
- 1.8.x
|
||||||
|
- 1.9.x
|
||||||
- tip
|
- tip
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
@ -15,13 +15,13 @@ Gin middleware/handler to enable CORS support.
|
|||||||
Download and install it:
|
Download and install it:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ go get gopkg.in/gin-contrib/cors.v1
|
$ go get github.com/gin-contrib/cors
|
||||||
```
|
```
|
||||||
|
|
||||||
Import it in your code:
|
Import it in your code:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import "gopkg.in/gin-contrib/cors.v1"
|
import "github.com/gin-contrib/cors"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Canonical example:
|
### Canonical example:
|
||||||
@ -32,7 +32,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gopkg.in/gin-contrib/cors.v1"
|
"github.com/gin-contrib/cors"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
8
cors.go
8
cors.go
@ -14,7 +14,7 @@ type Config struct {
|
|||||||
|
|
||||||
// AllowedOrigins is a list of origins a cross-domain request can be executed from.
|
// AllowedOrigins is a list of origins a cross-domain request can be executed from.
|
||||||
// If the special "*" value is present in the list, all origins will be allowed.
|
// If the special "*" value is present in the list, all origins will be allowed.
|
||||||
// Default value is ["*"]
|
// Default value is []
|
||||||
AllowOrigins []string
|
AllowOrigins []string
|
||||||
|
|
||||||
// AllowOriginFunc is a custom function to validate the origin. It take the origin
|
// AllowOriginFunc is a custom function to validate the origin. It take the origin
|
||||||
@ -28,8 +28,6 @@ type Config struct {
|
|||||||
|
|
||||||
// AllowedHeaders is list of non simple headers the client is allowed to use with
|
// AllowedHeaders is list of non simple headers the client is allowed to use with
|
||||||
// cross-domain requests.
|
// cross-domain requests.
|
||||||
// If the special "*" value is present in the list, all headers will be allowed.
|
|
||||||
// Default value is [] but "Origin" is always appended to the list.
|
|
||||||
AllowHeaders []string
|
AllowHeaders []string
|
||||||
|
|
||||||
// AllowCredentials indicates whether the request can include user credentials like
|
// AllowCredentials indicates whether the request can include user credentials like
|
||||||
@ -69,8 +67,8 @@ func (c Config) Validate() error {
|
|||||||
return errors.New("conflict settings: all origins disabled")
|
return errors.New("conflict settings: all origins disabled")
|
||||||
}
|
}
|
||||||
for _, origin := range c.AllowOrigins {
|
for _, origin := range c.AllowOrigins {
|
||||||
if !strings.HasPrefix(origin, "http://") && !strings.HasPrefix(origin, "https://") {
|
if origin != "*" && !strings.HasPrefix(origin, "http://") && !strings.HasPrefix(origin, "https://") {
|
||||||
return errors.New("bad origin: origins must include http:// or https://")
|
return errors.New("bad origin: origins must either be '*' or include http:// or https://")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user