github.com/msales/pkg/v3@v3.24.0/httpx/client.go (about)

     1  package httpx
     2  
     3  import (
     4  	"io"
     5  	"net"
     6  	"net/http"
     7  	"time"
     8  )
     9  
    10  // DefaultTransport is the default implementation of Transport and is
    11  // used by DefaultClient.
    12  var DefaultTransport = &http.Transport{
    13  	Proxy: http.ProxyFromEnvironment,
    14  	Dial: (&net.Dialer{
    15  		Timeout:   15 * time.Second,
    16  		KeepAlive: 90 * time.Second,
    17  	}).Dial,
    18  	TLSHandshakeTimeout: 3 * time.Second,
    19  }
    20  
    21  // DefaultClient is the default Client and is used by Get, Head, and Post.
    22  var DefaultClient = &http.Client{
    23  	Transport: DefaultTransport,
    24  }
    25  
    26  // Get issues a GET to the specified URL.
    27  func Get(url string) (resp *http.Response, err error) {
    28  	return DefaultClient.Get(url)
    29  }
    30  
    31  // Head issues a HEAD to the specified URL.
    32  func Head(url string) (resp *http.Response, err error) {
    33  	return DefaultClient.Head(url)
    34  }
    35  
    36  // Post issues a POST to the specified URL.
    37  func Post(url string, contentType string, body io.Reader) (resp *http.Response, err error) {
    38  	return DefaultClient.Post(url, contentType, body)
    39  }