-
Notifications
You must be signed in to change notification settings - Fork 546
/
goagent.go
46 lines (43 loc) · 1.03 KB
/
goagent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"log"
"net/http"
"os"
"time"
)
func main() {
// ca := &CA{"goagent", 2048}
// ca.Issue(true, "", 365*24*time.Hour)
addr := ":1080"
ln, err := Listen("tcp4", addr)
if err != nil {
log.Fatalf("Listen(\"tcp\", %s) failed: %s", addr, err)
}
h := Handler{
Listener: ln,
Log: log.New(os.Stderr, "INFO - ", 3),
Net: &SimpleNetwork{},
RequestPlugins: map[string]RequestPlugin{
"direct": &DirectRequestPlugin{},
"strip": &StripRequestPlugin{},
},
ResponsePlugins: map[string]ResponsePlugin{
"direct": &DirectResponsePlugin{},
},
RequestFilters: []RequestFilter{
&StripRequestFilter{},
&DirectRequestFilter{},
},
ResponseFilters: []ResponseFilter{
&DirectResponseFilter{},
},
}
s := &http.Server{
Handler: h,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
h.Log.Printf("ListenAndServe on %s\n", h.Listener.Addr().String())
h.Log.Fatal(s.Serve(h.Listener))
}