mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-10-28 22:17:17 +00:00
35 lines
899 B
Go
35 lines
899 B
Go
package responder
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/xtls/xray-core/common"
|
|
"github.com/xtls/xray-core/common/buf"
|
|
"github.com/xtls/xray-core/common/session"
|
|
"github.com/xtls/xray-core/transport"
|
|
"github.com/xtls/xray-core/transport/internet"
|
|
)
|
|
|
|
type Handler struct {
|
|
response []byte
|
|
}
|
|
|
|
func New(_ context.Context, config *Config) (*Handler, error) {
|
|
return &Handler{response: config.Response}, nil
|
|
}
|
|
|
|
// Process implements proxy.Outbound.
|
|
func (h *Handler) Process(ctx context.Context, link *transport.Link, _ internet.Dialer) error {
|
|
outbounds := session.OutboundsFromContext(ctx)
|
|
ob := outbounds[len(outbounds)-1]
|
|
ob.Name = "responder"
|
|
|
|
return link.Writer.WriteMultiBuffer(buf.MergeBytes(nil, h.response))
|
|
}
|
|
|
|
func init() {
|
|
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
|
return New(ctx, config.(*Config))
|
|
}))
|
|
}
|