|
@@ -0,0 +1,55 @@
|
|
1
|
+package main
|
|
2
|
+
|
|
3
|
+import (
|
|
4
|
+ "flag"
|
|
5
|
+ "fmt"
|
|
6
|
+ "log"
|
|
7
|
+ "net/http"
|
|
8
|
+ "os"
|
|
9
|
+
|
|
10
|
+ "github.com/elazarl/goproxy"
|
|
11
|
+)
|
|
12
|
+
|
|
13
|
+var f *os.File
|
|
14
|
+
|
|
15
|
+type Logger struct{}
|
|
16
|
+
|
|
17
|
+func (l *Logger) Printf(format string, v ...interface{}) {
|
|
18
|
+ log.Printf(format, v...)
|
|
19
|
+}
|
|
20
|
+
|
|
21
|
+func initLog() {
|
|
22
|
+ var err error
|
|
23
|
+ f, err = os.OpenFile("log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
|
24
|
+ if err != nil {
|
|
25
|
+ log.Fatal(err)
|
|
26
|
+ }
|
|
27
|
+
|
|
28
|
+ log.SetOutput(f)
|
|
29
|
+}
|
|
30
|
+
|
|
31
|
+func main() {
|
|
32
|
+ initLog()
|
|
33
|
+ defer func() {
|
|
34
|
+ if f != nil {
|
|
35
|
+ f.Close()
|
|
36
|
+ }
|
|
37
|
+ }()
|
|
38
|
+
|
|
39
|
+ var port = flag.String("p", "7080", "代理端口")
|
|
40
|
+ flag.Parse()
|
|
41
|
+ log.Println(fmt.Sprintf("开始监听 %s:%s", "127.0.0.1", *port))
|
|
42
|
+
|
|
43
|
+ proxy := goproxy.NewProxyHttpServer()
|
|
44
|
+ proxy.Logger = new(Logger)
|
|
45
|
+
|
|
46
|
+ // proxy.OnRequest(goproxy.ReqHostMatches(regexp.MustCompile(".*:443$"))).DoFunc(func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
|
|
47
|
+ // log.Println("==========================")
|
|
48
|
+ // log.Println(fmt.Sprintf("==========[%s] %s", r.Method, r.RequestURI))
|
|
49
|
+
|
|
50
|
+ // return r, nil
|
|
51
|
+ // })
|
|
52
|
+
|
|
53
|
+ proxy.Verbose = true
|
|
54
|
+ log.Fatal(http.ListenAndServe(":"+*port, proxy))
|
|
55
|
+}
|