Files
sing-box-extended-mirror/common/sniff/http.go
T

29 lines
695 B
Go
Raw Normal View History

2022-07-06 12:39:44 +08:00
package sniff
import (
std_bufio "bufio"
"context"
2025-04-04 16:21:50 +08:00
"errors"
2022-07-06 12:39:44 +08:00
"io"
"github.com/sagernet/sing-box/adapter"
C "github.com/sagernet/sing-box/constant"
2025-04-04 16:21:50 +08:00
E "github.com/sagernet/sing/common/exceptions"
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
)
2024-07-07 15:45:50 +08:00
func HTTPHost(_ context.Context, metadata *adapter.InboundContext, reader io.Reader) error {
2022-07-06 12:39:44 +08:00
request, err := http.ReadRequest(std_bufio.NewReader(reader))
if err != nil {
2025-04-04 16:21:50 +08:00
if errors.Is(err, io.ErrUnexpectedEOF) {
return E.Cause1(ErrNeedMoreData, err)
} else {
return err
}
2022-07-06 12:39:44 +08:00
}
2024-07-07 15:45:50 +08:00
metadata.Protocol = C.ProtocolHTTP
metadata.Domain = M.ParseSocksaddr(request.Host).AddrString()
return nil
2022-07-06 12:39:44 +08:00
}