transport_1_6.go 799 B

12345678910111213141516171819202122232425262728293031323334
  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. MaxIdleConnsPerHost: httpMaxConns.MaxIdleConnsPerHost,
  28. ResponseHeaderTimeout: httpTimeOut.HeaderTimeout,
  29. }
  30. return transport
  31. }