mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-16 21:56:40 -05:00
reverseproxy: Honor tls_except_port
for active health checks (#5591)
This commit is contained in:
parent
2b2addebb8
commit
7a69ae7571
1 changed files with 25 additions and 16 deletions
|
@ -306,16 +306,35 @@ func (h *Handler) doActiveHealthCheckForAllHosts() {
|
|||
// the host's health status fails.
|
||||
func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, upstream *Upstream) error {
|
||||
// create the URL for the request that acts as a health check
|
||||
scheme := "http"
|
||||
if ht, ok := h.Transport.(TLSTransport); ok && ht.TLSEnabled() {
|
||||
// this is kind of a hacky way to know if we should use HTTPS, but whatever
|
||||
scheme = "https"
|
||||
}
|
||||
u := &url.URL{
|
||||
Scheme: scheme,
|
||||
Scheme: "http",
|
||||
Host: hostAddr,
|
||||
}
|
||||
|
||||
// split the host and port if possible, override the port if configured
|
||||
host, port, err := net.SplitHostPort(hostAddr)
|
||||
if err != nil {
|
||||
host = hostAddr
|
||||
}
|
||||
if h.HealthChecks.Active.Port != 0 {
|
||||
port := strconv.Itoa(h.HealthChecks.Active.Port)
|
||||
u.Host = net.JoinHostPort(host, port)
|
||||
}
|
||||
|
||||
// this is kind of a hacky way to know if we should use HTTPS, but whatever
|
||||
if tt, ok := h.Transport.(TLSTransport); ok && tt.TLSEnabled() {
|
||||
u.Scheme = "https"
|
||||
|
||||
// if the port is in the except list, flip back to HTTP
|
||||
if ht, ok := h.Transport.(*HTTPTransport); ok {
|
||||
for _, exceptPort := range ht.TLS.ExceptPorts {
|
||||
if exceptPort == port {
|
||||
u.Scheme = "http"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if we have a provisioned uri, use that, otherwise use
|
||||
// the deprecated Path option
|
||||
if h.HealthChecks.Active.uri != nil {
|
||||
|
@ -325,16 +344,6 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, upstre
|
|||
u.Path = h.HealthChecks.Active.Path
|
||||
}
|
||||
|
||||
// adjust the port, if configured to be different
|
||||
if h.HealthChecks.Active.Port != 0 {
|
||||
portStr := strconv.Itoa(h.HealthChecks.Active.Port)
|
||||
host, _, err := net.SplitHostPort(hostAddr)
|
||||
if err != nil {
|
||||
host = hostAddr
|
||||
}
|
||||
u.Host = net.JoinHostPort(host, portStr)
|
||||
}
|
||||
|
||||
// attach dialing information to this request, as well as context values that
|
||||
// may be expected by handlers of this request
|
||||
ctx := h.ctx.Context
|
||||
|
|
Loading…
Reference in a new issue