mirror of
https://github.com/ehang-io/nps.git
synced 2025-07-04 22:00:43 +00:00
自动替换跨站点url
This commit is contained in:
parent
079d3dedad
commit
848c44b130
10
http.go
10
http.go
@ -69,6 +69,7 @@ func EncodeResponse(r *http.Response) ([]byte, error) {
|
|||||||
raw := bytes.NewBuffer([]byte{})
|
raw := bytes.NewBuffer([]byte{})
|
||||||
binary.Write(raw, binary.LittleEndian, []byte("sign"))
|
binary.Write(raw, binary.LittleEndian, []byte("sign"))
|
||||||
respBytes, err := httputil.DumpResponse(r, true)
|
respBytes, err := httputil.DumpResponse(r, true)
|
||||||
|
respBytes = replaceHost(respBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -97,3 +98,12 @@ func getHost(str string) (string, error) {
|
|||||||
}
|
}
|
||||||
return "", errors.New("没有找到解析的的host!")
|
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)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user