mirror of
https://github.com/openziti/zrok.git
synced 2024-11-07 08:44:14 +01:00
proxy components naming (#704)
This commit is contained in:
parent
ca9a2e7b7c
commit
ed1b30aa2c
@ -52,7 +52,7 @@ func NewBackend(cfg *BackendConfig) (*Backend, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
handler := util.NewProxyHandler(proxy)
|
handler := util.NewRequestsWrapper(proxy)
|
||||||
return &Backend{
|
return &Backend{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
listener: listener,
|
listener: listener,
|
||||||
|
@ -68,7 +68,7 @@ func NewFrontend(cfg *FrontendConfig) (*Frontend, error) {
|
|||||||
}
|
}
|
||||||
proxy.Transport = zTransport
|
proxy.Transport = zTransport
|
||||||
|
|
||||||
handler := authHandler(cfg.ShrToken, util.NewProxyHandler(proxy), "zrok", cfg, zCtx)
|
handler := authHandler(cfg.ShrToken, util.NewRequestsWrapper(proxy), "zrok", cfg, zCtx)
|
||||||
return &Frontend{
|
return &Frontend{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
zCtx: zCtx,
|
zCtx: zCtx,
|
||||||
|
@ -73,7 +73,7 @@ func NewHTTP(cfg *Config) (*HttpFrontend, error) {
|
|||||||
if err := configureOauthHandlers(context.Background(), cfg, cfg.Tls != nil); err != nil {
|
if err := configureOauthHandlers(context.Background(), cfg, cfg.Tls != nil); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
handler := authHandler(util.NewProxyHandler(proxy), cfg, key, zCtx)
|
handler := shareHandler(util.NewRequestsWrapper(proxy), cfg, key, zCtx)
|
||||||
return &HttpFrontend{
|
return &HttpFrontend{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
zCtx: zCtx,
|
zCtx: zCtx,
|
||||||
@ -151,7 +151,7 @@ func hostTargetReverseProxy(cfg *Config, ctx ziti.Context) *httputil.ReverseProx
|
|||||||
return &httputil.ReverseProxy{Director: director}
|
return &httputil.ReverseProxy{Director: director}
|
||||||
}
|
}
|
||||||
|
|
||||||
func authHandler(handler http.Handler, pcfg *Config, key []byte, ctx ziti.Context) http.HandlerFunc {
|
func shareHandler(handler http.Handler, pcfg *Config, key []byte, ctx ziti.Context) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
shrToken := resolveService(pcfg.HostMatch, r.Host)
|
shrToken := resolveService(pcfg.HostMatch, r.Host)
|
||||||
if shrToken != "" {
|
if shrToken != "" {
|
||||||
|
@ -6,13 +6,13 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type proxyHandler struct {
|
type requestsWrapper struct {
|
||||||
proxy *httputil.ReverseProxy
|
proxy *httputil.ReverseProxy
|
||||||
requests int32
|
requests int32
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProxyHandler(proxy *httputil.ReverseProxy) *proxyHandler {
|
func NewRequestsWrapper(proxy *httputil.ReverseProxy) *requestsWrapper {
|
||||||
handler := &proxyHandler{proxy: proxy}
|
handler := &requestsWrapper{proxy: proxy}
|
||||||
|
|
||||||
director := proxy.Director
|
director := proxy.Director
|
||||||
proxy.Director = func(req *http.Request) {
|
proxy.Director = func(req *http.Request) {
|
||||||
@ -23,10 +23,10 @@ func NewProxyHandler(proxy *httputil.ReverseProxy) *proxyHandler {
|
|||||||
return handler
|
return handler
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *proxyHandler) Requests() int32 {
|
func (self *requestsWrapper) Requests() int32 {
|
||||||
return atomic.LoadInt32(&self.requests)
|
return atomic.LoadInt32(&self.requests)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *proxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (self *requestsWrapper) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
self.proxy.ServeHTTP(w, r)
|
self.proxy.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user