func (h *Redirector) NewStatusAwareHandler(handler http.Handler) http.Handler {
	return h.status.NewStatusAwareHandler(handler, apiserver.StoppedHandler)
}
NewStatusAwareHandler returns a Handler that switches between different Handlers based on status.
package adapter
import (
	"crypto/tls"
	"net/http"
	"net/http/httputil"
	"net/url"
	"sync"
	"github.com/pingcap/tidb-dashboard/pkg/apiserver"
	"github.com/pingcap/tidb-dashboard/pkg/utils"
)
const (
	proxyHeader = "Via"
)
type Redirector struct {
	mu sync.RWMutex
	name      string
	tlsConfig *tls.Config
	address string
	proxy   *httputil.ReverseProxy
	status *utils.ServiceStatus
}
func NewRedirector(name string, tlsConfig *tls.Config) *Redirector {
	return &Redirector{
		name:      name,
		tlsConfig: tlsConfig,
		status:    utils.NewServiceStatus(),
	}
}
func (h *Redirector) SetAddress(addr string) {
	h.mu.Lock()
	defer h.mu.Unlock()
	if h.address == addr {
		return
	}
	if addr == "" {
		h.status.Stop()
		h.address = ""
		h.proxy = nil
		return
	}
	h.status.Start()
	h.address = addr
	target, _ := url.Parse(addr)  
	h.proxy = httputil.NewSingleHostReverseProxy(target)
	defaultDirector := h.proxy.Director
	h.proxy.Director = func(r *http.Request) {
		defaultDirector(r)
		r.Header.Set(proxyHeader, h.name)
	}
	if h.tlsConfig != nil {
		transport := http.DefaultTransport.(*http.Transport).Clone()
		transport.TLSClientConfig = h.tlsConfig
		h.proxy.Transport = transport
	}
}
func (h *Redirector) GetAddress() string {
	h.mu.RLock()
	defer h.mu.RUnlock()
	return h.address
}
func (h *Redirector) GetProxy() *httputil.ReverseProxy {
	h.mu.RLock()
	defer h.mu.RUnlock()
	return h.proxy
}
func (h *Redirector) TemporaryRedirect(w http.ResponseWriter, r *http.Request) {
	addr := h.GetAddress()
	if addr == "" {
		apiserver.StoppedHandler.ServeHTTP(w, r)
		return
	}
	http.Redirect(w, r, addr+r.RequestURI, http.StatusTemporaryRedirect)
}
func (h *Redirector) ReverseProxy(w http.ResponseWriter, r *http.Request) {
	proxy := h.GetProxy()
	if proxy == nil {
		apiserver.StoppedHandler.ServeHTTP(w, r)
		return
	}
	if len(r.Header.Get(proxyHeader)) > 0 {
		w.WriteHeader(http.StatusLoopDetected)
		return
	}
	proxy.ServeHTTP(w, r)
}