ソースを参照

Implement basic "full" proxy support

In this mode, it will act as a proxy, connecting to any website that is
requested from it.  The original `-proxy-url` flag is more like a
"fronting" server, whereas this new `-proxy` option is a generic proxy.
Lu Stadler 7 年 前
コミット
b8165ee623
共有1 個のファイルを変更した8 個の追加2 個の削除を含む
  1. 8 2
      go/fake-http/fake-http.go

+ 8 - 2
go/fake-http/fake-http.go

@ -29,6 +29,7 @@ var flags struct {
29 29
	proxyClientKey  string
30 30
31 31
	proxyMinikube bool
32
	proxy         bool
32 33
	cache         bool
33 34
}
34 35
@ -39,6 +40,7 @@ func init() {
39 40
	flag.StringVar(&flags.proxyClientKey, "proxy-client-key", "", "Client key to use when connecting to proxy")
40 41
41 42
	flag.BoolVar(&flags.proxyMinikube, "proxy-minikube", false, "Shortcut for -proxy-url https://$(minikube ip):8443 -proxy-client-cert ~/.minikube/client.crt -proxy-client-key ~/.minikube/client.key")
43
	flag.BoolVar(&flags.proxy, "proxy", false, "Proxy requests to any website")
42 44
	flag.BoolVar(&flags.cache, "cache", false, "Cache all requests")
43 45
}
44 46
@ -75,8 +77,12 @@ func main() {
75 77
		stub := responses.Match(req)
76 78
		haveCachedStub := flags.cache && stub != nil
77 79
		var resp *http.Response
78
		if flags.proxyURL != "" && !haveCachedStub {
79
			resp = respondWithProxy(flags.proxyURL, &cert, w, req)
80
		if (flags.proxy || flags.proxyURL != "") && !haveCachedStub {
81
			proxyURL := flags.proxyURL
82
			if flags.proxy {
83
				proxyURL = req.RequestURI
84
			}
85
			resp = respondWithProxy(proxyURL, &cert, w, req)
80 86
		} else {
81 87
			resp = respondWithStub(stub, w, req)
82 88
		}