testserver

addon-dailer
lqqyt2423 4 years ago
parent 80848bcc4b
commit bd1a1a3139

1
.gitignore vendored

@ -0,0 +1 @@
.env

@ -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

@ -5,3 +5,4 @@
- [x] http handler
- [x] http connect
- [ ] https handler
- [ ] cert

@ -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())
}

@ -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))
}

@ -1,3 +1,5 @@
module github.com/lqqyt2423/go-mitmproxy
go 1.14
require github.com/joho/godotenv v1.3.0

@ -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=
Loading…
Cancel
Save