transport_1_6.go 746 B

123456789101112131415161718192021222324252627282930
  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. MaxIdleConnsPerHost: httpMaxConns.MaxIdleConnsPerHost,
  24. ResponseHeaderTimeout: httpTimeOut.HeaderTimeout,
  25. }
  26. return transport
  27. }