HFish/core/protocol/httpx/http.go

30 lines
583 B
Go
Raw Normal View History

package httpx
import (
"net/http"
2019-08-14 18:47:18 +08:00
"github.com/elazarl/goproxy"
"net/url"
"fmt"
)
/*http 正向代理*/
2019-08-14 18:47:18 +08:00
func Start(addr string, proxyUrl string) {
2019-08-14 18:47:18 +08:00
gp := goproxy.NewProxyHttpServer()
pu, err := url.Parse(proxyUrl)
if err == nil {
gp.Tr.Proxy = http.ProxyURL(&url.URL{
Scheme: pu.Scheme,
Host: pu.Host,
})
}
2019-08-14 18:47:18 +08:00
gp.OnRequest().HandleConnect(goproxy.AlwaysMitm)
gp.OnRequest().DoFunc(func(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
// Report Send
fmt.Println(req.RemoteAddr)
return req, nil
})
http.ListenAndServe(addr, gp)
}