transport.go raw

   1  //go:build go1.13
   2  // +build go1.13
   3  
   4  // Copyright (c) 2015-2024 Jeevanandam M (jeeva@myjeeva.com), All rights reserved.
   5  // resty source code and usage is governed by a MIT style
   6  // license that can be found in the LICENSE file.
   7  
   8  package resty
   9  
  10  import (
  11  	"net"
  12  	"net/http"
  13  	"runtime"
  14  	"time"
  15  )
  16  
  17  func createTransport(localAddr net.Addr) *http.Transport {
  18  	dialer := &net.Dialer{
  19  		Timeout:   30 * time.Second,
  20  		KeepAlive: 30 * time.Second,
  21  		DualStack: true,
  22  	}
  23  	if localAddr != nil {
  24  		dialer.LocalAddr = localAddr
  25  	}
  26  	return &http.Transport{
  27  		Proxy:                 http.ProxyFromEnvironment,
  28  		DialContext:           transportDialContext(dialer),
  29  		ForceAttemptHTTP2:     true,
  30  		MaxIdleConns:          100,
  31  		IdleConnTimeout:       90 * time.Second,
  32  		TLSHandshakeTimeout:   10 * time.Second,
  33  		ExpectContinueTimeout: 1 * time.Second,
  34  		MaxIdleConnsPerHost:   runtime.GOMAXPROCS(0) + 1,
  35  	}
  36  }
  37