refact: refactored http_proxy fields

This commit is contained in:
evilsocket 2018-01-07 17:51:22 +01:00
parent 91ab98065f
commit a26295df8a

View file

@ -80,8 +80,8 @@ type HttpProxy struct {
server http.Server server http.Server
proxy *goproxy.ProxyHttpServer proxy *goproxy.ProxyHttpServer
pre_filter *ProxyFilter preFilter *ProxyFilter
post_filter *ProxyFilter postFilter *ProxyFilter
} }
func NewHttpProxy(s *session.Session) *HttpProxy { func NewHttpProxy(s *session.Session) *HttpProxy {
@ -90,8 +90,8 @@ func NewHttpProxy(s *session.Session) *HttpProxy {
proxy: goproxy.NewProxyHttpServer(), proxy: goproxy.NewProxyHttpServer(),
address: "", address: "",
redirection: nil, redirection: nil,
pre_filter: nil, preFilter: nil,
post_filter: nil, postFilter: nil,
} }
p.AddParam(session.NewIntParameter("http.port", "80", "", "HTTP port to redirect when the proxy is activated.")) p.AddParam(session.NewIntParameter("http.port", "80", "", "HTTP port to redirect when the proxy is activated."))
@ -116,7 +116,7 @@ func NewHttpProxy(s *session.Session) *HttpProxy {
req.URL.Scheme = "http" req.URL.Scheme = "http"
req.URL.Host = req.Host req.URL.Host = req.Host
// TODO: p.pre_filter.Process? // TODO: p.preFilter.Process?
p.proxy.ServeHTTP(w, req) p.proxy.ServeHTTP(w, req)
} else { } else {
@ -125,8 +125,8 @@ func NewHttpProxy(s *session.Session) *HttpProxy {
}) })
p.proxy.OnResponse(goproxy_html.IsHtml).Do(goproxy_html.HandleString(func(body string, ctx *goproxy.ProxyCtx) string { p.proxy.OnResponse(goproxy_html.IsHtml).Do(goproxy_html.HandleString(func(body string, ctx *goproxy.ProxyCtx) string {
if p.post_filter != nil { if p.postFilter != nil {
body = p.post_filter.Process(ctx.Req, body) body = p.postFilter.Process(ctx.Req, body)
} }
return body return body
})) }))
@ -183,13 +183,13 @@ func (p *HttpProxy) Start() error {
http_port = v.(int) http_port = v.(int)
} }
p.post_filter = nil p.postFilter = nil
if err, v := p.Param("http.proxy.post.filter").Get(p.Session); err != nil { if err, v := p.Param("http.proxy.post.filter").Get(p.Session); err != nil {
return err return err
} else { } else {
expression := v.(string) expression := v.(string)
if expression != "" { if expression != "" {
if err, p.post_filter = NewProxyFilter("post", expression); err != nil { if err, p.postFilter = NewProxyFilter("post", expression); err != nil {
return err return err
} else { } else {
log.Debug("Proxy POST filter set to '%s'.", expression) log.Debug("Proxy POST filter set to '%s'.", expression)