Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions modules/caddyhttp/reverseproxy/healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
// upstream host, the passive health check state will be reset because
// it will be garbage-collected. It is usually better for the dynamic
// upstream module to only return healthy, available backends instead.
Passive *PassiveHealthChecks `json:"passive,omitempty"`

Check failure on line 68 in modules/caddyhttp/reverseproxy/healthchecks.go

View workflow job for this annotation

GitHub Actions / govulncheck

undefined: PassiveHealthChecks
}

// ActiveHealthChecks holds configuration related to active
Expand All @@ -90,6 +90,11 @@
// this value is ignored.
Port int `json:"port,omitempty"`


// Configures the method of transport for the active health checker.
// The default transport is the handler's transport
TransportRaw json.RawMessage `json:"transport,omitempty" caddy:"namespace=http.reverse_proxy.transport inline_key=protocol"`

Check failure on line 96 in modules/caddyhttp/reverseproxy/healthchecks.go

View workflow job for this annotation

GitHub Actions / govulncheck

undefined: json

// HTTP headers to set on health check requests.
Headers http.Header `json:"headers,omitempty"`

Expand Down Expand Up @@ -128,6 +133,7 @@
// body of a healthy backend.
ExpectBody string `json:"expect_body,omitempty"`

transport http.RoundTripper `json:"-"``

Check failure on line 136 in modules/caddyhttp/reverseproxy/healthchecks.go

View workflow job for this annotation

GitHub Actions / govulncheck

expected ';', found `

Check failure on line 136 in modules/caddyhttp/reverseproxy/healthchecks.go

View workflow job for this annotation

GitHub Actions / lint (mac)

syntax error: unexpected literal `

Check failure on line 136 in modules/caddyhttp/reverseproxy/healthchecks.go

View workflow job for this annotation

GitHub Actions / lint (mac)

expected ';', found `

Check failure on line 136 in modules/caddyhttp/reverseproxy/healthchecks.go

View workflow job for this annotation

GitHub Actions / lint (mac)

syntax error: unexpected literal `

Check failure on line 136 in modules/caddyhttp/reverseproxy/healthchecks.go

View workflow job for this annotation

GitHub Actions / lint (mac)

syntax error: unexpected literal `
uri *url.URL
httpClient *http.Client
bodyRegexp *regexp.Regexp
Expand Down Expand Up @@ -174,10 +180,21 @@
}
a.uri = parsedURI
}

// Use handler's transport if no active one set
if a.TransportRaw != nil {
mod, err := ctx.LoadModule(a, "TransportRaw")
if err != nil {
return fmt.Errorf("loading transport: %v", err)
}
a.transport = mod.(http.RoundTripper)
} else {
a.transport = h.Transport
}

a.httpClient = &http.Client{
Timeout: timeout,
Transport: h.Transport,
Transport: a.transport,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
if !a.FollowRedirects {
return http.ErrUseLastResponse
Expand Down Expand Up @@ -252,7 +269,7 @@

// Count the request as failed if the response takes at least this
// long to receive.
UnhealthyLatency caddy.Duration `json:"unhealthy_latency,omitempty"`

Check failure on line 272 in modules/caddyhttp/reverseproxy/healthchecks.go

View workflow job for this annotation

GitHub Actions / govulncheck

raw string literal not terminated

Check failure on line 272 in modules/caddyhttp/reverseproxy/healthchecks.go

View workflow job for this annotation

GitHub Actions / lint (mac)

string not terminated (typecheck)

Check failure on line 272 in modules/caddyhttp/reverseproxy/healthchecks.go

View workflow job for this annotation

GitHub Actions / lint (mac)

raw string literal not terminated (typecheck)

Check failure on line 272 in modules/caddyhttp/reverseproxy/healthchecks.go

View workflow job for this annotation

GitHub Actions / lint (mac)

string not terminated) (typecheck)

logger *zap.Logger
}
Expand Down Expand Up @@ -405,12 +422,17 @@
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() {
// this is kind of a hacky way to know if we should use HTTPS
transport := h.HealthChecks.Active.transport
if transport == nil {
transport = h.Transport
}

if tt, ok := 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 && slices.Contains(ht.TLS.ExceptPorts, port) {
if ht, ok := transport.(*HTTPTransport); ok && slices.Contains(ht.TLS.ExceptPorts, port) {
u.Scheme = "http"
}
}
Expand Down Expand Up @@ -637,4 +659,4 @@
}
}
}(upstream.Host, failDuration)
}

Check failure on line 662 in modules/caddyhttp/reverseproxy/healthchecks.go

View workflow job for this annotation

GitHub Actions / govulncheck

expected ';', found 'EOF'

Check failure on line 662 in modules/caddyhttp/reverseproxy/healthchecks.go

View workflow job for this annotation

GitHub Actions / govulncheck

expected '}', found 'EOF'

Check failure on line 662 in modules/caddyhttp/reverseproxy/healthchecks.go

View workflow job for this annotation

GitHub Actions / lint (mac)

expected '}', found 'EOF' (typecheck)
Loading