feat(healthcheck): run TLS handshake after TCP dial if address has 443 port

This commit is contained in:
Quentin McGaw
2024-11-05 13:29:43 +00:00
parent 88fd9388e4
commit ddfcbe1bee

View File

@@ -2,9 +2,11 @@ package healthcheck
import (
"context"
"crypto/tls"
"errors"
"fmt"
"net"
"strings"
"time"
)
@@ -79,6 +81,22 @@ func (s *Server) healthCheck(ctx context.Context) (err error) {
return fmt.Errorf("dialing: %w", err)
}
if strings.HasSuffix(address, ":443") {
host, _, err := net.SplitHostPort(address)
if err != nil {
return fmt.Errorf("splitting host and port: %w", err)
}
tlsConfig := &tls.Config{
MinVersion: tls.VersionTLS12,
ServerName: host,
}
tlsConnection := tls.Client(connection, tlsConfig)
err = tlsConnection.HandshakeContext(ctx)
if err != nil {
return fmt.Errorf("running TLS handshake: %w", err)
}
}
err = connection.Close()
if err != nil {
return fmt.Errorf("closing connection: %w", err)