add resolver for router
This commit is contained in:
@ -29,8 +29,8 @@ func init() {
|
||||
}
|
||||
|
||||
type http2Handler struct {
|
||||
chain *chain.Chain
|
||||
bypass bypass.Bypass
|
||||
router *chain.Router
|
||||
logger logger.Logger
|
||||
md metadata
|
||||
}
|
||||
@ -43,17 +43,26 @@ func NewHandler(opts ...handler.Option) handler.Handler {
|
||||
|
||||
return &http2Handler{
|
||||
bypass: options.Bypass,
|
||||
router: (&chain.Router{}).
|
||||
WithLogger(options.Logger).
|
||||
WithResolver(options.Resolver),
|
||||
logger: options.Logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *http2Handler) Init(md md.Metadata) error {
|
||||
return h.parseMetadata(md)
|
||||
if err := h.parseMetadata(md); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
h.router.WithRetry(h.md.retryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// implements chain.Chainable interface
|
||||
func (h *http2Handler) WithChain(chain *chain.Chain) {
|
||||
h.chain = chain
|
||||
h.router.WithChain(chain)
|
||||
}
|
||||
|
||||
func (h *http2Handler) Handle(ctx context.Context, conn net.Conn) {
|
||||
@ -154,11 +163,7 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
|
||||
req.Header.Del("Proxy-Authorization")
|
||||
req.Header.Del("Proxy-Connection")
|
||||
|
||||
r := (&chain.Router{}).
|
||||
WithChain(h.chain).
|
||||
WithRetry(h.md.retryCount).
|
||||
WithLogger(h.logger)
|
||||
cc, err := r.Dial(ctx, "tcp", addr)
|
||||
cc, err := h.router.Dial(ctx, "tcp", addr)
|
||||
if err != nil {
|
||||
h.logger.Error(err)
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
@ -312,11 +317,7 @@ func (h *http2Handler) handleRequest(ctx context.Context, conn net.Conn, req *ht
|
||||
|
||||
req.Header.Del("Proxy-Authorization")
|
||||
|
||||
r := (&chain.Router{}).
|
||||
WithChain(h.chain).
|
||||
WithRetry(h.md.retryCount).
|
||||
WithLogger(h.logger)
|
||||
cc, err := r.Dial(ctx, network, addr)
|
||||
cc, err := h.router.Dial(ctx, network, addr)
|
||||
if err != nil {
|
||||
resp.StatusCode = http.StatusServiceUnavailable
|
||||
resp.Write(conn)
|
||||
|
Reference in New Issue
Block a user