2023-11-10 16:32:30 -05:00
|
|
|
//go:build !windows
|
2017-04-17 18:08:24 -04:00
|
|
|
|
|
|
|
package sockets
|
|
|
|
|
|
|
|
import (
|
2023-11-10 09:56:11 -05:00
|
|
|
"context"
|
2017-04-17 18:08:24 -04:00
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
const maxUnixSocketPathSize = len(syscall.RawSockaddrUnix{}.Path)
|
|
|
|
|
|
|
|
func configureUnixTransport(tr *http.Transport, proto, addr string) error {
|
|
|
|
if len(addr) > maxUnixSocketPathSize {
|
2023-11-10 16:32:30 -05:00
|
|
|
return fmt.Errorf("unix socket path %q is too long", addr)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
// No need for compression in local communications.
|
|
|
|
tr.DisableCompression = true
|
2023-11-10 09:56:11 -05:00
|
|
|
dialer := &net.Dialer{
|
|
|
|
Timeout: defaultTimeout,
|
|
|
|
}
|
|
|
|
tr.DialContext = func(ctx context.Context, _, _ string) (net.Conn, error) {
|
|
|
|
return dialer.DialContext(ctx, proto, addr)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func configureNpipeTransport(tr *http.Transport, proto, addr string) error {
|
|
|
|
return ErrProtocolNotAvailable
|
|
|
|
}
|
|
|
|
|
|
|
|
// DialPipe connects to a Windows named pipe.
|
|
|
|
// This is not supported on other OSes.
|
|
|
|
func DialPipe(_ string, _ time.Duration) (net.Conn, error) {
|
|
|
|
return nil, syscall.EAFNOSUPPORT
|
|
|
|
}
|