mirror of
https://github.com/eolinker/apinto
synced 2025-10-23 16:53:18 +08:00
去掉proxy_rewrite校验uri配置,并且弃用scheme
This commit is contained in:
@@ -3,27 +3,17 @@ package proxy_rewrite
|
||||
import "fmt"
|
||||
|
||||
type Config struct {
|
||||
Scheme string `json:"scheme" label:"协议"`
|
||||
Scheme string `json:"scheme" label:"协议(已废弃)"`
|
||||
URI string `json:"uri" label:"路径"`
|
||||
RegexURI []string `json:"regex_uri" label:"正则替换路径(regex_uri)"`
|
||||
RegexURI []string `json:"regex_uri" label:"正则替换路径(regex_uri)" description:"该数组需要配置两个正则,第一个是匹配正则,第二个是替换正则。"`
|
||||
Host string `json:"host" label:"Host"`
|
||||
Headers map[string]string `json:"headers" label:"请求头部"`
|
||||
Headers map[string]string `json:"headers" label:"请求头部" description:"可对转发请求的头部进行新增,修改,删除。配置的kv对,不存在则新增,已存在则进行覆盖重写,但需要注意特殊头部字段只能在后面添加新值而不能覆盖。value为空字符串表示删除。"`
|
||||
}
|
||||
|
||||
func (c *Config) doCheck() error {
|
||||
if c.Scheme == "" {
|
||||
c.Scheme = "http"
|
||||
} else if c.Scheme != "http" && c.Scheme != "https" {
|
||||
return fmt.Errorf(schemeErrInfo, c.Scheme)
|
||||
}
|
||||
|
||||
lenRegURI := len(c.RegexURI)
|
||||
|
||||
// URI和RegexURI至少选填其一
|
||||
if c.URI == "" && lenRegURI == 0 {
|
||||
return fmt.Errorf(uriErrInfo)
|
||||
}
|
||||
|
||||
//RegexURI切片要么为空,要么只有两个值,第一个值为正则匹配值,第二个是用于替换的正则字符串
|
||||
if lenRegURI > 0 && lenRegURI != 2 {
|
||||
return fmt.Errorf(regexpURIErrInfo, c.RegexURI)
|
||||
|
@@ -50,7 +50,6 @@ func (d *Driver) Create(id, name string, v interface{}, workers map[eosc.Require
|
||||
pw := &ProxyRewrite{
|
||||
Driver: d,
|
||||
id: id,
|
||||
scheme: conf.Scheme,
|
||||
uri: conf.URI,
|
||||
regexURI: conf.RegexURI,
|
||||
host: conf.Host,
|
||||
|
@@ -33,11 +33,6 @@ func (p *ProxyRewrite) DoFilter(ctx http_service.IHttpContext, next http_service
|
||||
}
|
||||
|
||||
func (p *ProxyRewrite) rewrite(ctx http_service.IHttpContext) error {
|
||||
//修改scheme
|
||||
if p.scheme != "" {
|
||||
ctx.Proxy().URI().SetScheme(p.scheme)
|
||||
}
|
||||
|
||||
//修改uri uri比regexURI更优先
|
||||
if p.uri != "" {
|
||||
ctx.Proxy().URI().SetPath(p.uri)
|
||||
@@ -80,7 +75,6 @@ func (p *ProxyRewrite) Reset(v interface{}, workers map[eosc.RequireId]interface
|
||||
return err
|
||||
}
|
||||
|
||||
p.scheme = conf.Scheme
|
||||
p.uri = conf.URI
|
||||
p.regexURI = conf.RegexURI
|
||||
p.host = conf.Host
|
||||
@@ -103,7 +97,6 @@ func (p *ProxyRewrite) Stop() error {
|
||||
}
|
||||
|
||||
func (p *ProxyRewrite) Destroy() {
|
||||
p.scheme = ""
|
||||
p.uri = ""
|
||||
p.regexURI = nil
|
||||
p.regexMatch = nil
|
||||
|
@@ -1,8 +1,6 @@
|
||||
package proxy_rewrite
|
||||
|
||||
var (
|
||||
schemeErrInfo = `[plugin proxy-rewrite config err] scheme must be in the set ["http","https"]. err scheme: %s `
|
||||
regexpURIErrInfo = `[plugin proxy-rewrite config err] regex_uri's length must be 0 or 2. err regexURI: %s `
|
||||
regexpErrInfo = `[plugin proxy-rewrite config err] compile regex_uri fail. err regexp: %s `
|
||||
uriErrInfo = `[plugin proxy-rewrite config err] uri or regexUri at least exist one item`
|
||||
)
|
||||
|
@@ -6,7 +6,7 @@ type Config struct {
|
||||
PrefixPath []*SPrefixPath `json:"prefix_path" label:"path前缀替换" switch:"path_type==='prefix'"`
|
||||
RegexPath []*SRegexPath `json:"regex_path" label:"path正则替换" switch:"path_type==='regex'"`
|
||||
NotMatchErr bool `json:"not_match_err" label:"path替换失败是否报错"`
|
||||
HostRewrite bool `json:"host_rewrite" label:"是否重写host" `
|
||||
HostRewrite bool `json:"host_rewrite" label:"是否重写host"`
|
||||
Host string `json:"host" label:"Host" switch:"host_rewrite===true"`
|
||||
Headers map[string]string `json:"headers" label:"请求头部"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user