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