mirror of
https://github.com/bettercap/bettercap
synced 2025-07-31 12:10:10 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
6c3157e9c4
commit
1adb542735
1 changed files with 11 additions and 8 deletions
|
@ -75,20 +75,23 @@ func (p *HTTPProxy) onResponseFilter(res *http.Response, ctx *goproxy.ProxyCtx)
|
||||||
|
|
||||||
// inject javascript code if specified and needed
|
// inject javascript code if specified and needed
|
||||||
if cType := getContentType(res); p.jsHook != "" && strings.Contains(cType, "text/html") {
|
if cType := getContentType(res); p.jsHook != "" && strings.Contains(cType, "text/html") {
|
||||||
log.Info("(%s) > injecting javascript (%d bytes) into %s for %s", core.Green(p.Name), len(p.jsHook), core.Yellow(req.Host+req.URL.Path), core.Bold(req.RemoteAddr))
|
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
||||||
raw, _ := ioutil.ReadAll(res.Body)
|
raw, _ := ioutil.ReadAll(res.Body)
|
||||||
html := strings.Replace(string(raw), "</head>", p.jsHook, -1)
|
|
||||||
|
|
||||||
newResp := goproxy.NewResponse(req, cType, res.StatusCode, html)
|
if strings.Contains(string(raw), "</head>") {
|
||||||
for k, vv := range res.Header {
|
log.Info("(%s) > injecting javascript (%d bytes) into %s for %s", core.Green(p.Name), len(p.jsHook), core.Yellow(req.Host+req.URL.Path), core.Bold(req.RemoteAddr))
|
||||||
for _, v := range vv {
|
html := strings.Replace(string(raw), "</head>", p.jsHook, -1)
|
||||||
newResp.Header.Add(k, v)
|
|
||||||
|
newResp := goproxy.NewResponse(req, cType, res.StatusCode, html)
|
||||||
|
for k, vv := range res.Header {
|
||||||
|
for _, v := range vv {
|
||||||
|
newResp.Header.Add(k, v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return newResp
|
return newResp
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue