misc: small fix or general refactoring i did not bother commenting

This commit is contained in:
evilsocket 2018-08-14 18:01:42 +02:00
parent 6c3157e9c4
commit 1adb542735
No known key found for this signature in database
GPG key ID: 1564D7F30393A456

View file

@ -75,20 +75,23 @@ func (p *HTTPProxy) onResponseFilter(res *http.Response, ctx *goproxy.ProxyCtx)
// inject javascript code if specified and needed
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()
raw, _ := ioutil.ReadAll(res.Body)
html := strings.Replace(string(raw), "</head>", p.jsHook, -1)
newResp := goproxy.NewResponse(req, cType, res.StatusCode, html)
for k, vv := range res.Header {
for _, v := range vv {
newResp.Header.Add(k, v)
if strings.Contains(string(raw), "</head>") {
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))
html := strings.Replace(string(raw), "</head>", p.jsHook, -1)
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