Support body rewrite
This commit is contained in:
@@ -87,16 +87,21 @@ func GetTimeout() int {
|
||||
return timeout
|
||||
}
|
||||
|
||||
func GetRewrites() map[string]string {
|
||||
func GetRewrites(hostMatch string) map[string]string {
|
||||
v := packable.NewString()
|
||||
conf.Get(nsConf, flagRewrites, v)
|
||||
m := make(map[string]string)
|
||||
for _, v := range strings.Split(v.String(), ",") {
|
||||
if len(v) == 0 {
|
||||
return m
|
||||
vs := strings.Split(v, ":")
|
||||
if len(v) < 3 {
|
||||
continue
|
||||
}
|
||||
from := v[:strings.Index(v, ":")]
|
||||
to := v[strings.Index(v, ":")+1:]
|
||||
host := vs[0]
|
||||
if host != hostMatch {
|
||||
continue
|
||||
}
|
||||
from := vs[1]
|
||||
to := strings.Join(vs[2:], ":")
|
||||
m[from] = to
|
||||
}
|
||||
return m
|
||||
|
||||
@@ -47,6 +47,7 @@ type fileConf struct {
|
||||
|
||||
func Init() error {
|
||||
log.SetFlags(log.Ldate | log.Ltime | log.Llongfile)
|
||||
log.SetFlags(log.Ltime | log.Lshortfile)
|
||||
if err := fromFile(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -120,7 +121,7 @@ func fromFlags() error {
|
||||
binds = append(binds, addFlag(flagRate, "100", "rate limit per second"))
|
||||
binds = append(binds, addFlag(flagBurst, "100", "rate limit burst"))
|
||||
binds = append(binds, addFlag(flagTimeout, "30", "seconds to wait for limiter"))
|
||||
binds = append(binds, addFlag(flagRewrites, "", "comma-separated regex:v to rewrite in response bodies"))
|
||||
binds = append(binds, addFlag(flagRewrites, "", "comma-separated from:replace:replacement to rewrite in response bodies"))
|
||||
flag.Parse()
|
||||
|
||||
for _, bind := range binds {
|
||||
|
||||
Reference in New Issue
Block a user