Merge pull request #8353 from randomswdev/jobservice-proxy

Make jobservice use the proxy env variables (including no_proxy)
This commit is contained in:
Wenkai Yin(尹文开) 2019-07-22 08:50:55 +08:00 committed by GitHub
commit 893de67eb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,18 +21,10 @@ import (
"io/ioutil" "io/ioutil"
"net" "net"
"net/http" "net/http"
"net/url"
"os"
"strings" "strings"
"time" "time"
"context" "context"
"github.com/goharbor/harbor/src/jobservice/common/utils"
)
const (
proxyEnvHTTP = "http_proxy"
proxyEnvHTTPS = "https_proxy"
) )
// Client for handling the hook events // Client for handling the hook events
@ -60,19 +52,7 @@ func NewClient(ctx context.Context) Client {
TLSHandshakeTimeout: 10 * time.Second, TLSHandshakeTimeout: 10 * time.Second,
ResponseHeaderTimeout: 10 * time.Second, ResponseHeaderTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second, ExpectContinueTimeout: 1 * time.Second,
} Proxy: http.ProxyFromEnvironment,
// Get the http/https proxies
proxyAddr, ok := os.LookupEnv(proxyEnvHTTP)
if !ok {
proxyAddr, ok = os.LookupEnv(proxyEnvHTTPS)
}
if ok && !utils.IsEmptyStr(proxyAddr) {
proxyURL, err := url.Parse(proxyAddr)
if err == nil {
transport.Proxy = http.ProxyURL(proxyURL)
}
} }
client := &http.Client{ client := &http.Client{