transport_1_7.go 851 B

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