Updating dependency github.com/elazarl/goproxy to version 947c36d

This commit is contained in:
Davanum Srinivas
2020-01-13 12:33:25 -05:00
parent fbfbd10c28
commit a6d72ab713
33 changed files with 144 additions and 72 deletions

View File

@@ -16,6 +16,8 @@ type ProxyHttpServer struct {
// session variable must be aligned in i386
// see http://golang.org/src/pkg/sync/atomic/doc.go#L41
sess int64
// KeepDestinationHeaders indicates the proxy should retain any headers present in the http.Response before proxying
KeepDestinationHeaders bool
// setting Verbose to true will log information on each request sent to the proxy
Verbose bool
Logger *log.Logger
@@ -31,9 +33,11 @@ type ProxyHttpServer struct {
var hasPort = regexp.MustCompile(`:\d+$`)
func copyHeaders(dst, src http.Header) {
for k, _ := range dst {
dst.Del(k)
func copyHeaders(dst, src http.Header, keepDestHeaders bool) {
if !keepDestHeaders {
for k := range dst {
dst.Del(k)
}
}
for k, vs := range src {
for _, v := range vs {
@@ -134,7 +138,7 @@ func (proxy *ProxyHttpServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
if origBody != resp.Body {
resp.Header.Del("Content-Length")
}
copyHeaders(w.Header(), resp.Header)
copyHeaders(w.Header(), resp.Header, proxy.KeepDestinationHeaders)
w.WriteHeader(resp.StatusCode)
nr, err := io.Copy(w, resp.Body)
if err := resp.Body.Close(); err != nil {
@@ -144,7 +148,7 @@ func (proxy *ProxyHttpServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
}
}
// New proxy server, logs to StdErr by default
// NewProxyHttpServer creates and returns a proxy server, logging to stderr by default
func NewProxyHttpServer() *ProxyHttpServer {
proxy := ProxyHttpServer{
Logger: log.New(os.Stderr, "", log.LstdFlags),
@@ -154,9 +158,9 @@ func NewProxyHttpServer() *ProxyHttpServer {
NonproxyHandler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
http.Error(w, "This is a proxy server. Does not respond to non-proxy requests.", 500)
}),
Tr: &http.Transport{TLSClientConfig: tlsClientSkipVerify,
Proxy: http.ProxyFromEnvironment},
Tr: &http.Transport{TLSClientConfig: tlsClientSkipVerify, Proxy: http.ProxyFromEnvironment},
}
proxy.ConnectDial = dialerFromEnv(&proxy)
return &proxy
}