|
|
@ -11,11 +11,14 @@ package tshttpproxy
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const proxyAuthHeader = "Proxy-Authorization"
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
func init() {
|
|
|
|
condSetTransportGetProxyConnectHeader = func(tr *http.Transport) {
|
|
|
|
condSetTransportGetProxyConnectHeader = func(tr *http.Transport) {
|
|
|
|
tr.GetProxyConnectHeader = func(ctx context.Context, proxyURL *url.URL, target string) (http.Header, error) {
|
|
|
|
tr.GetProxyConnectHeader = func(ctx context.Context, proxyURL *url.URL, target string) (http.Header, error) {
|
|
|
@ -27,7 +30,16 @@ func init() {
|
|
|
|
if v == "" {
|
|
|
|
if v == "" {
|
|
|
|
return nil, nil
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return http.Header{"Authorization": []string{v}}, nil
|
|
|
|
return http.Header{proxyAuthHeader: []string{v}}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
tr.OnProxyConnectResponse = func(ctx context.Context, proxyURL *url.URL, connectReq *http.Request, res *http.Response) error {
|
|
|
|
|
|
|
|
auth := connectReq.Header.Get(proxyAuthHeader)
|
|
|
|
|
|
|
|
const truncLen = 20
|
|
|
|
|
|
|
|
if len(auth) > truncLen {
|
|
|
|
|
|
|
|
auth = fmt.Sprintf("%s...(%d total bytes)", auth[:truncLen], len(auth))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("tshttpproxy: CONNECT response from %v for target %q (auth %q): %v", proxyURL, connectReq.Host, auth, res.Status)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|