@@ -44,29 +44,31 @@ goproxy server. Fiddler is a GUI app not designed to be ran like a server for mu
44
44
45
45
To get a taste of ` goproxy ` , a basic HTTP/HTTPS transparent proxy
46
46
47
-
48
- package main
49
-
50
- import (
51
- "github.com/elazarl/goproxy"
52
- "log"
53
- "net/http"
54
- )
55
-
56
- func main() {
57
- proxy := goproxy.NewProxyHttpServer()
58
- proxy.Verbose = true
59
- log.Fatal(http.ListenAndServe(":8080", proxy))
60
- }
61
-
47
+ ``` go
48
+ package main
49
+
50
+ import (
51
+ " github.com/elazarl/goproxy"
52
+ " log"
53
+ " net/http"
54
+ )
55
+
56
+ func main () {
57
+ proxy := goproxy.NewProxyHttpServer ()
58
+ proxy.Verbose = true
59
+ log.Fatal (http.ListenAndServe (" :8080" , proxy))
60
+ }
61
+ ```
62
62
63
63
This line will add ` X-GoProxy: yxorPoG-X ` header to all requests sent through the proxy
64
64
65
- proxy.OnRequest().DoFunc(
66
- func(r *http.Request,ctx *goproxy.ProxyCtx)(*http.Request,*http.Response) {
67
- r.Header.Set("X-GoProxy","yxorPoG-X")
68
- return r,nil
69
- })
65
+ ``` go
66
+ proxy.OnRequest ().DoFunc (
67
+ func (r *http .Request ,ctx *goproxy .ProxyCtx )(*http .Request ,*http .Response ) {
68
+ r.Header .Set (" X-GoProxy" ," yxorPoG-X" )
69
+ return r,nil
70
+ })
71
+ ```
70
72
71
73
` DoFunc ` will process all incoming requests to the proxy. It will add a header to the request
72
74
and return it. The proxy will send the modified request.
@@ -76,15 +78,17 @@ have discarded the request and sent the new response to the client.
76
78
77
79
In order to refuse connections to reddit at work time
78
80
79
- proxy.OnRequest(goproxy.DstHostIs("www.reddit.com")).DoFunc(
80
- func(r *http.Request,ctx *goproxy.ProxyCtx)(*http.Request,*http.Response) {
81
- if h,_,_ := time.Now().Clock(); h >= 8 && h <= 17 {
82
- return r,goproxy.NewResponse(r,
83
- goproxy.ContentTypeText,http.StatusForbidden,
84
- "Don't waste your time!")
85
- }
86
- return r,nil
87
- })
81
+ ``` go
82
+ proxy.OnRequest (goproxy.DstHostIs (" www.reddit.com" )).DoFunc (
83
+ func (r *http .Request ,ctx *goproxy .ProxyCtx )(*http .Request ,*http .Response ) {
84
+ if h,_,_ := time.Now ().Clock (); h >= 8 && h <= 17 {
85
+ return r,goproxy.NewResponse (r,
86
+ goproxy.ContentTypeText ,http.StatusForbidden ,
87
+ " Don't waste your time!" )
88
+ }
89
+ return r,nil
90
+ })
91
+ ```
88
92
89
93
` DstHostIs ` returns a ` ReqCondition ` , that is a function receiving a ` Request ` and returning a boolean
90
94
we will only process requests that matches the condition. ` DstHostIs("www.reddit.com") ` will return
0 commit comments