transport_1_7.go 904 B

123456789101112131415161718192021222324252627282930313233343536
  1. // +build go1.7
  2. package oss
  3. import (
  4. "net"
  5. "net/http"
  6. "time"
  7. )
  8. func newTransport(conn *Conn, config *Config) *http.Transport {
  9. httpTimeOut := conn.config.HTTPTimeout
  10. httpMaxConns := conn.config.HTTPMaxConns
  11. // New Transport
  12. transport := &http.Transport{
  13. Dial: func(netw, addr string) (net.Conn, error) {
  14. d := net.Dialer{
  15. Timeout: httpTimeOut.ConnectTimeout,
  16. KeepAlive: 30 * time.Second,
  17. }
  18. if config.LocalAddr != nil {
  19. d.LocalAddr = config.LocalAddr
  20. }
  21. conn, err := d.Dial(netw, addr)
  22. if err != nil {
  23. return nil, err
  24. }
  25. return newTimeoutConn(conn, httpTimeOut.ReadWriteTimeout, httpTimeOut.LongTimeout), nil
  26. },
  27. MaxIdleConns: httpMaxConns.MaxIdleConns,
  28. MaxIdleConnsPerHost: httpMaxConns.MaxIdleConnsPerHost,
  29. IdleConnTimeout: httpTimeOut.IdleConnTimeout,
  30. ResponseHeaderTimeout: httpTimeOut.HeaderTimeout,
  31. }
  32. return transport
  33. }