http_test.go 835 B

123456789101112131415161718192021222324252627282930
  1. package sniff_test
  2. import (
  3. "context"
  4. "strings"
  5. "testing"
  6. "github.com/sagernet/sing-box/adapter"
  7. "github.com/sagernet/sing-box/common/sniff"
  8. "github.com/stretchr/testify/require"
  9. )
  10. func TestSniffHTTP1(t *testing.T) {
  11. t.Parallel()
  12. pkt := "GET / HTTP/1.1\r\nHost: www.google.com\r\nAccept: */*\r\n\r\n"
  13. var metadata adapter.InboundContext
  14. err := sniff.HTTPHost(context.Background(), &metadata, strings.NewReader(pkt))
  15. require.NoError(t, err)
  16. require.Equal(t, metadata.Domain, "www.google.com")
  17. }
  18. func TestSniffHTTP1WithPort(t *testing.T) {
  19. t.Parallel()
  20. pkt := "GET / HTTP/1.1\r\nHost: www.gov.cn:8080\r\nAccept: */*\r\n\r\n"
  21. var metadata adapter.InboundContext
  22. err := sniff.HTTPHost(context.Background(), &metadata, strings.NewReader(pkt))
  23. require.NoError(t, err)
  24. require.Equal(t, metadata.Domain, "www.gov.cn")
  25. }