2022-07-06 12:39:44 +08:00
|
|
|
package sniff
|
|
|
|
|
|
|
|
import (
|
|
|
|
std_bufio "bufio"
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/sagernet/sing-box/adapter"
|
|
|
|
C "github.com/sagernet/sing-box/constant"
|
2023-04-19 16:05:11 +08:00
|
|
|
M "github.com/sagernet/sing/common/metadata"
|
2022-07-08 23:03:57 +08:00
|
|
|
"github.com/sagernet/sing/protocol/http"
|
2022-07-06 12:39:44 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func HTTPHost(ctx context.Context, reader io.Reader) (*adapter.InboundContext, error) {
|
|
|
|
request, err := http.ReadRequest(std_bufio.NewReader(reader))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-04-19 16:05:11 +08:00
|
|
|
return &adapter.InboundContext{Protocol: C.ProtocolHTTP, Domain: M.ParseSocksaddr(request.Host).AddrString()}, nil
|
2022-07-06 12:39:44 +08:00
|
|
|
}
|