wip: oci
This commit is contained in:
35
tool/http.go
Normal file
35
tool/http.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package tool
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func NewClient(skipTlsVerify bool, proxy string) *http.Client {
|
||||
client := &http.Client{}
|
||||
|
||||
// Configure TLS
|
||||
if skipTlsVerify {
|
||||
transport := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
client.Transport = transport
|
||||
}
|
||||
|
||||
// Configure proxy
|
||||
if proxy != "" {
|
||||
proxyURL, err := url.Parse(proxy)
|
||||
if err == nil {
|
||||
if client.Transport == nil {
|
||||
client.Transport = &http.Transport{}
|
||||
}
|
||||
|
||||
if transport, ok := client.Transport.(*http.Transport); ok {
|
||||
transport.Proxy = http.ProxyURL(proxyURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
Reference in New Issue
Block a user