diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4763af2 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +.PHONY: mitmproxy +mitmproxy: + go build -o mitmproxy cmd/mitmproxy/main.go + +.PHONY: testserver +testserver: + go build -o testserver cmd/testserver/main.go + +.PHONY: clean +clean: + rm -f mitmproxy testserver diff --git a/README.md b/README.md index f5a5171..8b121f4 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,4 @@ - [x] http handler - [x] http connect - [ ] https handler +- [ ] cert diff --git a/bin/main.go b/cmd/mitmproxy/main.go similarity index 73% rename from bin/main.go rename to cmd/mitmproxy/main.go index 9bd8a28..da9f9b9 100644 --- a/bin/main.go +++ b/cmd/mitmproxy/main.go @@ -3,14 +3,14 @@ package main import ( "log" - proxy "github.com/lqqyt2423/go-mitmproxy" + "github.com/lqqyt2423/go-mitmproxy/proxy" ) func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) opts := &proxy.Options{ - Addr: ":8080", + Addr: ":9080", } log.Fatal(proxy.NewProxy(opts).Start()) } diff --git a/cmd/testserver/main.go b/cmd/testserver/main.go new file mode 100644 index 0000000..bcbe839 --- /dev/null +++ b/cmd/testserver/main.go @@ -0,0 +1,39 @@ +package main + +import ( + "log" + "net/http" + "os" + + _ "github.com/joho/godotenv/autoload" +) + +var cert string = os.Getenv("SERVER_CERT_FILE") +var key string = os.Getenv("SERVER_KEY_FILE") +var httpAddr string = ":8080" +var httpsAddr string = ":8443" + +type Server struct{} + +func (server *Server) ServeHTTP(rw http.ResponseWriter, req *http.Request) { + log.Printf("%v %v", req.Method, req.URL.String()) + _, _ = rw.Write([]byte("hello world\n")) +} + +func main() { + go func() { + server := &http.Server{ + Addr: httpAddr, + Handler: &Server{}, + } + log.Printf("http server listen at %v\n", httpAddr) + log.Fatal(server.ListenAndServe()) + }() + + server := &http.Server{ + Addr: httpsAddr, + Handler: &Server{}, + } + log.Printf("https server listen at %v\n", httpsAddr) + log.Fatal(server.ListenAndServeTLS(cert, key)) +} diff --git a/go.mod b/go.mod index e779ada..76223c9 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/lqqyt2423/go-mitmproxy go 1.14 + +require github.com/joho/godotenv v1.3.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..ead7071 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= diff --git a/proxy.go b/proxy/proxy.go similarity index 100% rename from proxy.go rename to proxy/proxy.go