diff --git a/Makefile b/Makefile index 531c595..fa9348c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: mitmproxy dummycert +all: mitmproxy .PHONY: mitmproxy mitmproxy: diff --git a/addon/web/web.go b/addon/web/web.go index ac8f162..e47ce0e 100644 --- a/addon/web/web.go +++ b/addon/web/web.go @@ -36,41 +36,36 @@ func (web *WebAddon) echo(w http.ResponseWriter, r *http.Request) { type WebAddon struct { addon.Base - addr string - upgrader *websocket.Upgrader - serverMux *http.ServeMux - server *http.Server + upgrader *websocket.Upgrader conns []*concurrentConn connsMu sync.RWMutex } -func NewWebAddon() *WebAddon { +func NewWebAddon(addr string) *WebAddon { web := new(WebAddon) - web.addr = ":9081" web.upgrader = &websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { return true }, } - web.serverMux = new(http.ServeMux) - web.serverMux.HandleFunc("/echo", web.echo) + serverMux := new(http.ServeMux) + serverMux.HandleFunc("/echo", web.echo) - // web.serverMux.Handle("/", http.FileServer(http.Dir("addon/web/client/build"))) fsys, err := fs.Sub(assets, "client/build") if err != nil { panic(err) } - web.serverMux.Handle("/", http.FileServer(http.FS(fsys))) + serverMux.Handle("/", http.FileServer(http.FS(fsys))) - web.server = &http.Server{Addr: web.addr, Handler: web.serverMux} + server := &http.Server{Addr: addr, Handler: serverMux} log = log.WithField("in", "WebAddon") web.conns = make([]*concurrentConn, 0) go func() { - log.Infof("server start listen at %v\n", web.addr) - err := web.server.ListenAndServe() + log.Infof("web interface start listen at %v\n", addr) + err := server.ListenAndServe() log.Error(err) }() diff --git a/cmd/mitmproxy/main.go b/cmd/mitmproxy/main.go index 7081e31..020ec1b 100644 --- a/cmd/mitmproxy/main.go +++ b/cmd/mitmproxy/main.go @@ -12,6 +12,7 @@ import ( type Config struct { addr string + webAddr string dump string // dump filename dumpLevel int // dump level } @@ -20,6 +21,7 @@ func loadConfig() *Config { config := new(Config) flag.StringVar(&config.addr, "addr", ":9080", "proxy listen addr") + flag.StringVar(&config.webAddr, "web_addr", ":9081", "web interface listen addr") flag.StringVar(&config.dump, "dump", "", "dump filename") flag.IntVar(&config.dumpLevel, "dump_level", 0, "dump level: 0 - header, 1 - header + body") flag.Parse() @@ -53,7 +55,7 @@ func main() { } p.AddAddon(&addon.Decoder{}) - p.AddAddon(web.NewWebAddon()) + p.AddAddon(web.NewWebAddon(config.webAddr)) log.Fatal(p.Start()) }