sing-box/inbound/http.go

44 lines
1.2 KiB
Go
Raw Normal View History

2022-07-01 19:34:02 +08:00
package inbound
import (
std_bufio "bufio"
"context"
"net"
"github.com/sagernet/sing-box/adapter"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/log"
2022-07-02 14:07:50 +08:00
"github.com/sagernet/sing-box/option"
2022-07-08 23:03:57 +08:00
"github.com/sagernet/sing/common/auth"
M "github.com/sagernet/sing/common/metadata"
"github.com/sagernet/sing/protocol/http"
2022-07-01 19:34:02 +08:00
)
var _ adapter.Inbound = (*HTTP)(nil)
type HTTP struct {
myInboundAdapter
authenticator auth.Authenticator
}
2022-07-02 22:55:10 +08:00
func NewHTTP(ctx context.Context, router adapter.Router, logger log.Logger, tag string, options option.SimpleInboundOptions) *HTTP {
2022-07-01 19:34:02 +08:00
inbound := &HTTP{
myInboundAdapter{
protocol: C.TypeHTTP,
network: []string{C.NetworkTCP},
ctx: ctx,
router: router,
logger: logger,
tag: tag,
listenOptions: options.ListenOptions,
},
auth.NewAuthenticator(options.Users),
}
inbound.connHandler = inbound
return inbound
}
func (h *HTTP) NewConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext) error {
return http.HandleConnection(ctx, conn, std_bufio.NewReader(conn), h.authenticator, h.upstreamHandler(metadata), M.Metadata{})
}