| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "github.com/elazarl/goproxy" |
| 5 | "log" |
| 6 | "flag" |
| 7 | "net/http" |
| 8 | ) |
| 9 | |
| 10 | func main() { |
| 11 | verbose := flag.Bool("v", false, "should every proxy request be logged to stdout") |
| 12 | addr := flag.String("addr", ":8080", "proxy listen address") |
| 13 | flag.Parse() |
| 14 | proxy := goproxy.NewProxyHttpServer() |
| 15 | proxy.OnRequest().HandleConnect(goproxy.AlwaysMitm) |
| 16 | proxy.OnRequest().DoFunc(func (req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) { |
| 17 | if req.URL.Scheme == "https" { |
| 18 | req.URL.Scheme = "http" |
| 19 | } |
| 20 | return req, nil |
| 21 | }) |
| 22 | proxy.Verbose = *verbose |
| 23 | log.Fatal(http.ListenAndServe(*addr, proxy)) |
| 24 | } |