/
dhproxy.go
46 lines (40 loc) · 928 Bytes
/
dhproxy.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
// Dumping HTTP Proxy
// dRbiG
// See LICENSE.txt
package main
import (
"flag"
"fmt"
"github.com/elazarl/goproxy"
"log"
"net/http"
"os"
"strconv"
)
func die(msg string, code int) {
log.Fatalln(msg)
os.Exit(code)
}
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [options] PORT\n", os.Args[0])
flag.PrintDefaults()
}
var host string
flag.StringVar(&host, "h", "127.0.0.1", "HTTP server bind HOST")
flag.Parse()
if len(flag.Args()) < 1 {
die("You have to specify a port!", 2)
}
port, err := strconv.Atoi(flag.Args()[0])
if err != nil || port <= 0 {
die("Port has to be a positive integer!", 2)
}
proxy := goproxy.NewProxyHttpServer()
proxy.OnRequest().DoFunc(
func(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
fmt.Println(req.RequestURI)
return req, nil
})
log.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%d", host, port), proxy))
}