...

Source file src/github.com/docker/go-connections/sockets/sockets.go

Documentation: github.com/docker/go-connections/sockets

     1  // Package sockets provides helper functions to create and configure Unix or TCP sockets.
     2  package sockets
     3  
     4  import (
     5  	"errors"
     6  	"net"
     7  	"net/http"
     8  	"time"
     9  )
    10  
    11  const defaultTimeout = 10 * time.Second
    12  
    13  // ErrProtocolNotAvailable is returned when a given transport protocol is not provided by the operating system.
    14  var ErrProtocolNotAvailable = errors.New("protocol not available")
    15  
    16  // ConfigureTransport configures the specified [http.Transport] according to the specified proto
    17  // and addr.
    18  //
    19  // If the proto is unix (using a unix socket to communicate) or npipe the compression is disabled.
    20  // For other protos, compression is enabled. If you want to manually enable/disable compression,
    21  // make sure you do it _after_ any subsequent calls to ConfigureTransport is made against the same
    22  // [http.Transport].
    23  func ConfigureTransport(tr *http.Transport, proto, addr string) error {
    24  	switch proto {
    25  	case "unix":
    26  		return configureUnixTransport(tr, proto, addr)
    27  	case "npipe":
    28  		return configureNpipeTransport(tr, proto, addr)
    29  	default:
    30  		tr.Proxy = http.ProxyFromEnvironment
    31  		tr.DisableCompression = false
    32  		tr.DialContext = (&net.Dialer{
    33  			Timeout: defaultTimeout,
    34  		}).DialContext
    35  	}
    36  	return nil
    37  }
    38  

View as plain text