Skip to content

Commit d58a790

Browse files
authored
Merge pull request #175 from ZombieHippie/patch-1
README.md Add syntax highlighting go, and programmable typo
2 parents 8976e52 + 15382fc commit d58a790

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed

README.md

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,31 @@ goproxy server. Fiddler is a GUI app not designed to be ran like a server for mu
4444

4545
To get a taste of `goproxy`, a basic HTTP/HTTPS transparent proxy
4646

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+
```
6262

6363
This line will add `X-GoProxy: yxorPoG-X` header to all requests sent through the proxy
6464

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+
```
7072

7173
`DoFunc` will process all incoming requests to the proxy. It will add a header to the request
7274
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.
7678

7779
In order to refuse connections to reddit at work time
7880

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+
```
8892

8993
`DstHostIs` returns a `ReqCondition`, that is a function receiving a `Request` and returning a boolean
9094
we will only process requests that matches the condition. `DstHostIs("www.reddit.com")` will return

0 commit comments

Comments
 (0)