// Initialise the http.Transport for go1.7+ func (ci *ConfigInfo) initTransport(t *http.Transport) { t.DialContext = func(ctx context.Context, network, address string) (net.Conn, error) { return dialContextTimeout(ctx, network, address, ci.ConnectTimeout, ci.Timeout) } t.IdleConnTimeout = 60 * time.Second t.ExpectContinueTimeout = ci.ConnectTimeout }
// installHTTPDialShim patches the default HTTP transport so // that it fails when an attempt is made to dial a non-local // host. // // Note that this is Go version dependent because in Go 1.7 and above, // the DialContext field was introduced (and set in http.DefaultTransport) // which overrides the Dial field. func installHTTPDialShim(t *http.Transport) { t.DialContext = func(ctxt context.Context, network, addr string) (net.Conn, error) { if !OutgoingAccessAllowed && !isLocalAddr(addr) { return nil, fmt.Errorf("access to address %q not allowed", addr) } return ctxtDialer.DialContext(ctxt, network, addr) } }
// Enable the passed http.Transport for Unix domain socket connections. func EnableTransport(t *http.Transport) { t.DialContext = WrapDialContext(t.DialContext) }