示例#1
0
func parseOptions(o Options) (Options, error) {
	if o.Limits.MaxMemBodyBytes <= 0 {
		o.Limits.MaxMemBodyBytes = netutils.DefaultMemBufferBytes
	}
	if o.Timeouts.Read <= time.Duration(0) {
		o.Timeouts.Read = DefaultHttpReadTimeout
	}
	if o.Timeouts.Dial <= time.Duration(0) {
		o.Timeouts.Dial = DefaultHttpDialTimeout
	}
	if o.Timeouts.TlsHandshake <= time.Duration(0) {
		o.Timeouts.TlsHandshake = DefaultTlsHandshakeTimeout
	}
	if o.KeepAlive.Period <= time.Duration(0) {
		o.KeepAlive.Period = DefaultKeepAlivePeriod
	}
	if o.KeepAlive.MaxIdleConnsPerHost <= 0 {
		o.KeepAlive.MaxIdleConnsPerHost = DefaultMaxIdleConnsPerHost
	}

	if o.Hostname == "" {
		h, err := os.Hostname()
		if err == nil {
			o.Hostname = h
		}
	}
	if o.TimeProvider == nil {
		o.TimeProvider = &timetools.RealTime{}
	}
	if o.ShouldFailover == nil {
		// Failover on errors for 2 times maximum on GET requests only.
		o.ShouldFailover = failover.And(failover.AttemptsLe(2), failover.IsNetworkError, failover.RequestMethodEq("GET"))
	}
	return o, nil
}
示例#2
0
文件: httploc.go 项目: jbardin/vulcan
func parseOptions(o Options) (Options, error) {
	if o.Timeouts.Read <= time.Duration(0) {
		o.Timeouts.Read = DefaultHttpReadTimeout
	}
	if o.Timeouts.Dial <= time.Duration(0) {
		o.Timeouts.Dial = DefaultHttpDialTimeout
	}

	if o.Hostname == "" {
		h, err := os.Hostname()
		if err == nil {
			o.Hostname = h
		}
	}
	if o.TimeProvider == nil {
		o.TimeProvider = &timetools.RealTime{}
	}
	if o.ShouldFailover == nil {
		// Failover on errors for 2 times maximum on GET requests only.
		o.ShouldFailover = failover.And(failover.MaxAttempts(2), failover.OnErrors, failover.OnGets)
	}
	return o, nil
}