Compare commits

...

8 Commits
v1.2 ... master

Author SHA1 Message Date
Bo-Yi Wu
51f0ef8b07 Update .travis.yml 2017-09-17 10:20:32 +08:00
Bo-Yi Wu
88488351b0 update 1.9
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-08-27 00:58:24 +08:00
Javier Provecho Fernandez
567de19169 Merge pull request #27 from easonlin404/readme
Remove unnecessary comments.
2017-07-08 10:09:47 +02:00
Eason Lin
e641d4ab82 undo comments, cross support for wildcard origin 2017-07-03 00:16:58 +08:00
Eason Lin
1238974274 Change comments to ‘Default value is []’ 2017-06-28 13:58:35 +08:00
Matthew Baird
f894742c19 add support for wildcard cors origin (#24) 2017-06-27 23:27:08 -05:00
Eason Lin
796e03648c Remove unnecessary comments. 2017-06-28 08:45:17 +08:00
Eason Lin
5c9b3fa52c Unify ‘github.com’ wording with code. (#26) 2017-06-27 11:18:33 -05:00
3 changed files with 7 additions and 8 deletions

View File

@ -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:

View File

@ -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"
) )

View File

@ -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