add Transport override option for active health checks
parent
99073eaa33
commit
c92e374cd9
|
@ -90,6 +90,9 @@ type ActiveHealthChecks struct {
|
||||||
// this value is ignored.
|
// this value is ignored.
|
||||||
Port int `json:"port,omitempty"`
|
Port int `json:"port,omitempty"`
|
||||||
|
|
||||||
|
// The transport to use for health checks. If not set, the handler's transport is used
|
||||||
|
Transport http.RoundTripper `json:"transport,omitempty"`
|
||||||
|
|
||||||
// HTTP headers to set on health check requests.
|
// HTTP headers to set on health check requests.
|
||||||
Headers http.Header `json:"headers,omitempty"`
|
Headers http.Header `json:"headers,omitempty"`
|
||||||
|
|
||||||
|
@ -175,9 +178,14 @@ func (a *ActiveHealthChecks) Provision(ctx caddy.Context, h *Handler) error {
|
||||||
a.uri = parsedURI
|
a.uri = parsedURI
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use handler's transport if no active one set
|
||||||
|
if a.Transport == nil {
|
||||||
|
a.Transport = h.Transport
|
||||||
|
}
|
||||||
|
|
||||||
a.httpClient = &http.Client{
|
a.httpClient = &http.Client{
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
Transport: h.Transport,
|
Transport: a.Transport,
|
||||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||||
if !a.FollowRedirects {
|
if !a.FollowRedirects {
|
||||||
return http.ErrUseLastResponse
|
return http.ErrUseLastResponse
|
||||||
|
@ -393,12 +401,17 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, networ
|
||||||
u.Host = net.JoinHostPort(host, port)
|
u.Host = net.JoinHostPort(host, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is kind of a hacky way to know if we should use HTTPS, but whatever
|
// this is kind of a hacky way to know if we should use HTTPS
|
||||||
if tt, ok := h.Transport.(TLSTransport); ok && tt.TLSEnabled() {
|
transport := h.HealthChecks.Active.Transport
|
||||||
|
if transport == nil {
|
||||||
|
transport = h.Transport
|
||||||
|
}
|
||||||
|
|
||||||
|
if tt, ok := transport.(TLSTransport); ok && tt.TLSEnabled() {
|
||||||
u.Scheme = "https"
|
u.Scheme = "https"
|
||||||
|
|
||||||
// if the port is in the except list, flip back to HTTP
|
// if the port is in the except list, flip back to HTTP
|
||||||
if ht, ok := h.Transport.(*HTTPTransport); ok && slices.Contains(ht.TLS.ExceptPorts, port) {
|
if ht, ok := transport.(*HTTPTransport); ok && slices.Contains(ht.TLS.ExceptPorts, port) {
|
||||||
u.Scheme = "http"
|
u.Scheme = "http"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue