remove unnecessary conn
This commit is contained in:
@ -24,7 +24,6 @@ import (
|
||||
"github.com/go-gost/gost/v3/pkg/logger"
|
||||
md "github.com/go-gost/gost/v3/pkg/metadata"
|
||||
"github.com/go-gost/gost/v3/pkg/registry"
|
||||
http2_util "github.com/go-gost/x/internal/util/http2"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -76,13 +75,18 @@ func (h *http2Handler) Handle(ctx context.Context, conn net.Conn, opts ...handle
|
||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||
}()
|
||||
|
||||
cc, ok := conn.(*http2_util.ServerConn)
|
||||
if !ok {
|
||||
v, ok := conn.(md.Metadatable)
|
||||
if !ok || v == nil {
|
||||
err := errors.New("wrong connection type")
|
||||
log.Error(err)
|
||||
return err
|
||||
}
|
||||
return h.roundTrip(ctx, cc.Writer(), cc.Request(), log)
|
||||
md := v.GetMetadata()
|
||||
return h.roundTrip(ctx,
|
||||
md.Get("w").(http.ResponseWriter),
|
||||
md.Get("r").(*http.Request),
|
||||
log,
|
||||
)
|
||||
}
|
||||
|
||||
// NOTE: there is an issue (golang/go#43989) will cause the client hangs
|
||||
|
@ -81,8 +81,8 @@ func (h *tapHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
|
||||
defer conn.Close()
|
||||
|
||||
log := h.options.Logger
|
||||
cc, ok := conn.(*tap_util.Conn)
|
||||
if !ok || cc.Config() == nil {
|
||||
v, _ := conn.(md.Metadatable)
|
||||
if v == nil {
|
||||
err := errors.New("tap: wrong connection type")
|
||||
log.Error(err)
|
||||
return err
|
||||
@ -118,7 +118,8 @@ func (h *tapHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), target.Addr)
|
||||
}
|
||||
|
||||
h.handleLoop(ctx, conn, raddr, cc.Config(), log)
|
||||
config := v.GetMetadata().Get("config").(*tap_util.Config)
|
||||
h.handleLoop(ctx, conn, raddr, config, log)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -84,8 +84,8 @@ func (h *tunHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
|
||||
|
||||
log := h.options.Logger
|
||||
|
||||
cc, ok := conn.(*tun_util.Conn)
|
||||
if !ok || cc.Config() == nil {
|
||||
v, _ := conn.(md.Metadatable)
|
||||
if v == nil {
|
||||
err := errors.New("tun: wrong connection type")
|
||||
log.Error(err)
|
||||
return err
|
||||
@ -121,7 +121,8 @@ func (h *tunHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), target.Addr)
|
||||
}
|
||||
|
||||
h.handleLoop(ctx, conn, raddr, cc.Config(), log)
|
||||
config := v.GetMetadata().Get("config").(*tun_util.Config)
|
||||
h.handleLoop(ctx, conn, raddr, config, log)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user