| 75 | } |
| 76 | |
| 77 | func NewHTTPProxy(s *session.Session, tag string) *HTTPProxy { |
| 78 | p := &HTTPProxy{ |
| 79 | Name: "http.proxy", |
| 80 | Proxy: goproxy.NewProxyHttpServer(), |
| 81 | Sess: s, |
| 82 | Stripper: NewSSLStripper(s, false), |
| 83 | isTLS: false, |
| 84 | doRedirect: true, |
| 85 | Server: nil, |
| 86 | Blacklist: make([]string, 0), |
| 87 | Whitelist: make([]string, 0), |
| 88 | tag: session.AsTag(tag), |
| 89 | } |
| 90 | |
| 91 | p.Proxy.Verbose = false |
| 92 | p.Proxy.Logger = dummyLogger{p} |
| 93 | |
| 94 | p.Proxy.NonproxyHandler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { |
| 95 | if p.doProxy(req) { |
| 96 | if !p.isTLS { |
| 97 | req.URL.Scheme = "http" |
| 98 | } |
| 99 | req.URL.Host = req.Host |
| 100 | p.Proxy.ServeHTTP(w, req) |
| 101 | } |
| 102 | }) |
| 103 | |
| 104 | p.Proxy.OnRequest().HandleConnect(goproxy.AlwaysMitm) |
| 105 | p.Proxy.OnRequest().DoFunc(p.onRequestFilter) |
| 106 | p.Proxy.OnResponse().DoFunc(p.onResponseFilter) |
| 107 | |
| 108 | return p |
| 109 | } |
| 110 | |
| 111 | func (p *HTTPProxy) Debug(format string, args ...interface{}) { |
| 112 | p.Sess.Events.Log(log.DEBUG, p.tag+format, args...) |