Skip to content

Commit

Permalink
自动替换跨站点url
Browse files Browse the repository at this point in the history
  • Loading branch information
刘河 committed Nov 8, 2018
1 parent 079d3de commit 848c44b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}

0 comments on commit 848c44b

Please sign in to comment.