Przeglądaj źródła

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 lat temu
rodzic
commit
b8165ee623
1 zmienionych plików z 8 dodań i 2 usunięć
  1. 8 2
      go/fake-http/fake-http.go

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

29
	proxyClientKey  string
29
	proxyClientKey  string
30
30
31
	proxyMinikube bool
31
	proxyMinikube bool
32
	proxy         bool
32
	cache         bool
33
	cache         bool
33
}
34
}
34
35
39
	flag.StringVar(&flags.proxyClientKey, "proxy-client-key", "", "Client key to use when connecting to proxy")
40
	flag.StringVar(&flags.proxyClientKey, "proxy-client-key", "", "Client key to use when connecting to proxy")
40
41
41
	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")
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
	flag.BoolVar(&flags.cache, "cache", false, "Cache all requests")
44
	flag.BoolVar(&flags.cache, "cache", false, "Cache all requests")
43
}
45
}
44
46
75
		stub := responses.Match(req)
77
		stub := responses.Match(req)
76
		haveCachedStub := flags.cache && stub != nil
78
		haveCachedStub := flags.cache && stub != nil
77
		var resp *http.Response
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
		} else {
86
		} else {
81
			resp = respondWithStub(stub, w, req)
87
			resp = respondWithStub(stub, w, req)
82
		}
88
		}