health_gate.go
1 // Copyright 2026 Alibaba Group Holding Ltd. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package mitmproxy 16 17 import ( 18 "os" 19 "sync/atomic" 20 21 "github.com/alibaba/opensandbox/egress/pkg/constants" 22 ) 23 24 // HealthGate coordinates HTTP GET /healthz with transparent mitm readiness (listener, iptables, CA export). 25 type HealthGate struct { 26 required bool // transparent mitm enabled via env 27 ready atomic.Bool 28 } 29 30 func NewHealthGate() *HealthGate { 31 required := constants.IsTruthy(os.Getenv(constants.EnvMitmproxyTransparent)) 32 g := &HealthGate{required: required} 33 if !required { 34 g.ready.Store(true) 35 } 36 return g 37 } 38 39 func (g *HealthGate) MarkStackReady() { 40 if g != nil { 41 g.ready.Store(true) 42 } 43 } 44 45 func (g *HealthGate) MitmPending() bool { 46 if g == nil { 47 return false 48 } 49 return g.required && !g.ready.Load() 50 }