sockets_unix.go 926 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. //go:build !windows
  2. package sockets
  3. import (
  4. "context"
  5. "fmt"
  6. "net"
  7. "net/http"
  8. "syscall"
  9. "time"
  10. )
  11. const maxUnixSocketPathSize = len(syscall.RawSockaddrUnix{}.Path)
  12. func configureUnixTransport(tr *http.Transport, proto, addr string) error {
  13. if len(addr) > maxUnixSocketPathSize {
  14. return fmt.Errorf("unix socket path %q is too long", addr)
  15. }
  16. // No need for compression in local communications.
  17. tr.DisableCompression = true
  18. dialer := &net.Dialer{
  19. Timeout: defaultTimeout,
  20. }
  21. tr.DialContext = func(ctx context.Context, _, _ string) (net.Conn, error) {
  22. return dialer.DialContext(ctx, proto, addr)
  23. }
  24. return nil
  25. }
  26. func configureNpipeTransport(tr *http.Transport, proto, addr string) error {
  27. return ErrProtocolNotAvailable
  28. }
  29. // DialPipe connects to a Windows named pipe.
  30. // This is not supported on other OSes.
  31. func DialPipe(_ string, _ time.Duration) (net.Conn, error) {
  32. return nil, syscall.EAFNOSUPPORT
  33. }