| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 | package http_testimport (	"testing"	"v2ray.com/core/common/compare"	. "v2ray.com/core/common/protocol/http")func TestHTTPHeaders(t *testing.T) {	cases := []struct {		input  string		domain string		err    bool	}{		{			input: `GET /tutorials/other/top-20-mysql-best-practices/ HTTP/1.1Host: net.tutsplus.comUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: en-us,en;q=0.5Accept-Encoding: gzip,deflateAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7Keep-Alive: 300Connection: keep-aliveCookie: PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120Pragma: no-cacheCache-Control: no-cache`,			domain: "net.tutsplus.com",		},		{			input: `POST /foo.php HTTP/1.1Host: localhostUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: en-us,en;q=0.5Accept-Encoding: gzip,deflateAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7Keep-Alive: 300Connection: keep-aliveReferer: http://localhost/test.phpContent-Type: application/x-www-form-urlencodedContent-Length: 43 first_name=John&last_name=Doe&action=Submit`,			domain: "localhost",		},		{			input: `X /foo.php HTTP/1.1Host: localhostUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: en-us,en;q=0.5Accept-Encoding: gzip,deflateAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7Keep-Alive: 300Connection: keep-aliveReferer: http://localhost/test.phpContent-Type: application/x-www-form-urlencodedContent-Length: 43 first_name=John&last_name=Doe&action=Submit`,			domain: "",			err:    true,		},		{			input: `GET /foo.php HTTP/1.1User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: en-us,en;q=0.5Accept-Encoding: gzip,deflateAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7Keep-Alive: 300Connection: keep-aliveReferer: http://localhost/test.phpContent-Type: application/x-www-form-urlencodedContent-Length: 43Host: localhostfirst_name=John&last_name=Doe&action=Submit`,			domain: "",			err:    true,		},		{			input:  `GET /tutorials/other/top-20-mysql-best-practices/ HTTP/1.1`,			domain: "",			err:    true,		},	}	for _, test := range cases {		header, err := SniffHTTP([]byte(test.input))		if test.err {			if err == nil {				t.Errorf("Expect error but nil, in test: %v", test)			}		} else {			if err != nil {				t.Errorf("Expect no error but actually %s in test %v", err.Error(), test)			}			if err := compare.StringEqualWithDetail(header.Domain(), test.domain); err != nil {				t.Error(err)			}		}	}}
 |