http.go 695 B

12345678910111213141516171819202122232425262728
  1. package sniff
  2. import (
  3. std_bufio "bufio"
  4. "context"
  5. "errors"
  6. "io"
  7. "github.com/sagernet/sing-box/adapter"
  8. C "github.com/sagernet/sing-box/constant"
  9. E "github.com/sagernet/sing/common/exceptions"
  10. M "github.com/sagernet/sing/common/metadata"
  11. "github.com/sagernet/sing/protocol/http"
  12. )
  13. func HTTPHost(_ context.Context, metadata *adapter.InboundContext, reader io.Reader) error {
  14. request, err := http.ReadRequest(std_bufio.NewReader(reader))
  15. if err != nil {
  16. if errors.Is(err, io.ErrUnexpectedEOF) {
  17. return E.Cause1(ErrNeedMoreData, err)
  18. } else {
  19. return err
  20. }
  21. }
  22. metadata.Protocol = C.ProtocolHTTP
  23. metadata.Domain = M.ParseSocksaddr(request.Host).AddrString()
  24. return nil
  25. }