github.com/cli/cli@v1.14.1-0.20210902173923-1af6a669e342/internal/httpunix/transport.go (about)

     1  // package httpunix provides an http.RoundTripper which dials a server via a unix socket.
     2  package httpunix
     3  
     4  import (
     5  	"net"
     6  	"net/http"
     7  )
     8  
     9  // NewRoundTripper returns an http.RoundTripper which sends requests via a unix
    10  // socket at socketPath.
    11  func NewRoundTripper(socketPath string) http.RoundTripper {
    12  	dial := func(network, addr string) (net.Conn, error) {
    13  		return net.Dial("unix", socketPath)
    14  	}
    15  
    16  	return &http.Transport{
    17  		Dial:              dial,
    18  		DialTLS:           dial,
    19  		DisableKeepAlives: true,
    20  	}
    21  }