自动替换跨站点url

This commit is contained in:
刘河 2018-11-08 19:53:30 +08:00
parent 079d3dedad
commit 848c44b130

10
http.go
View File

@ -69,6 +69,7 @@ func EncodeResponse(r *http.Response) ([]byte, error) {
raw := bytes.NewBuffer([]byte{})
binary.Write(raw, binary.LittleEndian, []byte("sign"))
respBytes, err := httputil.DumpResponse(r, true)
respBytes = replaceHost(respBytes)
if err != nil {
return nil, err
}
@ -97,3 +98,12 @@ func getHost(str string) (string, error) {
}
return "", errors.New("没有找到解析的的host!")
}
func replaceHost(resp []byte) []byte {
str := string(resp)
for _, v := range config.SiteList {
str = strings.Replace(str, v.Url+":"+string(v.Port), v.Host, -1)
str = strings.Replace(str, v.Url, v.Host, -1)
}
return []byte(str)
}