mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-30 10:11:23 +02:00
34 lines
757 B
Go
34 lines
757 B
Go
package dockerclient
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"net"
|
|
"net/http"
|
|
"net/url"
|
|
"time"
|
|
)
|
|
|
|
func newHTTPClient(u *url.URL, tlsConfig *tls.Config, timeout time.Duration) *http.Client {
|
|
httpTransport := &http.Transport{
|
|
TLSClientConfig: tlsConfig,
|
|
}
|
|
|
|
switch u.Scheme {
|
|
default:
|
|
httpTransport.Dial = func(proto, addr string) (net.Conn, error) {
|
|
return net.DialTimeout(proto, addr, timeout)
|
|
}
|
|
case "unix":
|
|
socketPath := u.Path
|
|
unixDial := func(proto, addr string) (net.Conn, error) {
|
|
return net.DialTimeout("unix", socketPath, timeout)
|
|
}
|
|
httpTransport.Dial = unixDial
|
|
// Override the main URL object so the HTTP lib won't complain
|
|
u.Scheme = "http"
|
|
u.Host = "unix.sock"
|
|
u.Path = ""
|
|
}
|
|
return &http.Client{Transport: httpTransport}
|
|
}
|