mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2026-01-25 02:15:47 +08:00
增加CORS自适应跨域
This commit is contained in:
19
pkg/serverconfigs/shared/http_cors_header_config.go
Normal file
19
pkg/serverconfigs/shared/http_cors_header_config.go
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package shared
|
||||
|
||||
// HTTPCORSHeaderConfig 参考 https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
||||
type HTTPCORSHeaderConfig struct {
|
||||
IsOn bool `yaml:"isOn" json:"isOn"`
|
||||
AllowMethods []string `yaml:"allowMethods" json:"allowMethods"` // TODO
|
||||
AllowOrigin string `yaml:"allowOrigin" json:"allowOrigin"` // TODO
|
||||
AllowCredentials bool `yaml:"allowCredentials" json:"allowCredentials"` // TODO
|
||||
ExposeHeaders []string `yaml:"exposeHeaders" json:"exposeHeaders"` // TODO
|
||||
MaxAge int32 `yaml:"maxAge" json:"maxAge"` // TODO
|
||||
RequestHeaders []string `yaml:"requestHeaders" json:"requestHeaders"` // TODO
|
||||
RequestMethod string `yaml:"requestMethod" json:"requestMethod"` // TODO
|
||||
}
|
||||
|
||||
func (this *HTTPCORSHeaderConfig) Init() error {
|
||||
return nil
|
||||
}
|
||||
@@ -14,6 +14,7 @@ type HTTPHeaderPolicy struct {
|
||||
DeleteHeaders []string `yaml:"deleteHeaders" json:"deleteHeaders"` // 删除的Header
|
||||
|
||||
Expires *HTTPExpireHeaderConfig `yaml:"expires" json:"expires"` // TODO
|
||||
CORS *HTTPCORSHeaderConfig `yaml:"cors" json:"cors"`
|
||||
|
||||
setHeaderNames []string
|
||||
deleteHeaderMap map[string]bool // header => bool
|
||||
@@ -36,6 +37,14 @@ func (this *HTTPHeaderPolicy) Init() error {
|
||||
this.deleteHeaderMap[strings.ToUpper(header)] = true
|
||||
}
|
||||
|
||||
// cors
|
||||
if this.CORS != nil {
|
||||
err := this.CORS.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user