diff --git a/client_test.go b/client_test.go index 033284d197..2678d0db84 100644 --- a/client_test.go +++ b/client_test.go @@ -808,7 +808,7 @@ func TestClientDoWithCustomHeaders(t *testing.T) { uri := "/foo/bar/baz?a=b&cd=12" headers := map[string]string{ "Foo": "bar", - "Host": "xxx.com", + "Host": "example.com", "Content-Type": "asdfsdf", "a-b-c-d-f": "", } diff --git a/server_timing_test.go b/server_timing_test.go index 6ed1cae031..1e7f6f2112 100644 --- a/server_timing_test.go +++ b/server_timing_test.go @@ -317,7 +317,7 @@ func newFakeListener(requestsCount, clientsCount, requestsPerConn int, request s var ( fakeResponse = []byte("Hello, world!") getRequest = "GET /foobar?baz HTTP/1.1\r\nHost: google.com\r\nUser-Agent: aaa/bbb/ccc/ddd/eee Firefox Chrome MSIE Opera\r\n" + - "Referer: http://xxx.com/aaa?bbb=ccc\r\nCookie: foo=bar; baz=baraz; aa=aakslsdweriwereowriewroire\r\n\r\n" + "Referer: http://example.com/aaa?bbb=ccc\r\nCookie: foo=bar; baz=baraz; aa=aakslsdweriwereowriewroire\r\n\r\n" postRequest = fmt.Sprintf("POST /foobar?baz HTTP/1.1\r\nHost: google.com\r\nContent-Type: foo/bar\r\nContent-Length: %d\r\n"+ "User-Agent: Opera Chrome MSIE Firefox and other/1.2.34\r\nReferer: http://google.com/aaaa/bbb/ccc\r\n"+ "Cookie: foo=bar; baz=baraz; aa=aakslsdweriwereowriewroire\r\n\r\n%s", diff --git a/uri_test.go b/uri_test.go index a605b46219..c7f02817d7 100644 --- a/uri_test.go +++ b/uri_test.go @@ -107,28 +107,33 @@ func TestURIUpdate(t *testing.T) { t.Parallel() // full uri - testURIUpdate(t, "http://foo.bar/baz?aaa=22#aaa", "https://aa.com/bb", "https://aa.com/bb") + testURIUpdate(t, "http://example.net/dir/path1.html?param1=val1#fragment1", "https://example.com/dir/path2.html", "https://example.com/dir/path2.html") // empty uri - testURIUpdate(t, "http://aaa.com/aaa.html?234=234#add", "", "http://aaa.com/aaa.html?234=234#add") + testURIUpdate(t, "http://example.com/dir/path1.html?param1=val1#fragment1", "", "http://example.com/dir/path1.html?param1=val1#fragment1") // request uri - testURIUpdate(t, "ftp://aaa/xxx/yyy?aaa=bb#aa", "/boo/bar?xx", "ftp://aaa/boo/bar?xx") + testURIUpdate(t, "http://example.com/dir/path1.html?param1=val1#fragment1", "/dir/path2.html?param2=val2#fragment2", "http://example.com/dir/path2.html?param2=val2#fragment2") + + // schema + testURIUpdate(t, "http://example.com/dir/path1.html?param1=val1#fragment1", "https://example.com/dir/path1.html?param1=val1#fragment1", "https://example.com/dir/path1.html?param1=val1#fragment1") // relative uri - testURIUpdate(t, "http://foo.bar/baz/xxx.html?aaa=22#aaa", "bb.html?xx=12#pp", "http://foo.bar/baz/bb.html?xx=12#pp") - testURIUpdate(t, "http://xx/a/b/c/d", "../qwe/p?zx=34", "http://xx/a/b/qwe/p?zx=34") - testURIUpdate(t, "https://qqq/aaa.html?foo=bar", "?baz=434&aaa#xcv", "https://qqq/aaa.html?baz=434&aaa#xcv") - testURIUpdate(t, "http://foo.bar/baz", "~a/%20b=c,тест?йцу=ке", "http://foo.bar/~a/%20b=c,%D1%82%D0%B5%D1%81%D1%82?йцу=ке") - testURIUpdate(t, "http://foo.bar/baz", "/qwe#fragment", "http://foo.bar/qwe#fragment") - testURIUpdate(t, "http://foobar/baz/xxx", "aaa.html#bb?cc=dd&ee=dfd", "http://foobar/baz/aaa.html#bb?cc=dd&ee=dfd") + testURIUpdate(t, "http://example.com/baz/xxx.html?aaa=22#aaa", "bb.html?xx=12#pp", "http://example.com/baz/bb.html?xx=12#pp") + testURIUpdate(t, "http://example.com/a/b/c/d", "../qwe/p?zx=34", "http://example.com/a/b/qwe/p?zx=34") + testURIUpdate(t, "http://example.com/aaa.html?foo=bar", "?baz=434&aaa#xcv", "http://example.com/aaa.html?baz=434&aaa#xcv") + testURIUpdate(t, "http://example.com/baz", "~a/%20b=c,тест?йцу=ке", "http://example.com/~a/%20b=c,%D1%82%D0%B5%D1%81%D1%82?йцу=ке") + testURIUpdate(t, "http://example.com/baz", "/qwe#fragment", "http://example.com/qwe#fragment") + testURIUpdate(t, "http://example.com/baz/xxx", "aaa.html#bb?cc=dd&ee=dfd", "http://example.com/baz/aaa.html#bb?cc=dd&ee=dfd") // hash - testURIUpdate(t, "http://foo.bar/baz#aaa", "#fragment", "http://foo.bar/baz#fragment") + testURIUpdate(t, "http://example.com/#fragment1", "#fragment2", "http://example.com/#fragment2") // uri without scheme - testURIUpdate(t, "https://foo.bar/baz", "//aaa.bbb/cc?dd", "https://aaa.bbb/cc?dd") - testURIUpdate(t, "http://foo.bar/baz", "//aaa.bbb/cc?dd", "http://aaa.bbb/cc?dd") + testURIUpdate(t, "https://example.net/dir/path1.html", "//example.com/dir/path2.html", "https://example.com/dir/path2.html") + testURIUpdate(t, "http://example.net/dir/path1.html", "//example.com/dir/path2.html", "http://example.com/dir/path2.html") + // host with port + testURIUpdate(t, "http://example.net/", "//example.com:8080/", "http://example.com:8080/") } func testURIUpdate(t *testing.T, base, update, result string) { @@ -220,7 +225,7 @@ func TestURICopyTo(t *testing.T) { t.Fatalf("URICopyTo fail, u: \n%+v\ncopyu: \n%+v\n", u, copyU) //nolint:govet } - u.UpdateBytes([]byte("https://google.com/foo?bar=baz&baraz#qqqq")) + u.UpdateBytes([]byte("https://example.com/foo?bar=baz&baraz#qqqq")) u.CopyTo(©U) if !reflect.DeepEqual(u, copyU) { //nolint:govet t.Fatalf("URICopyTo fail, u: \n%+v\ncopyu: \n%+v\n", u, copyU) //nolint:govet @@ -234,27 +239,27 @@ func TestURIFullURI(t *testing.T) { var args Args // empty scheme, path and hash - testURIFullURI(t, "", "foobar.com", "", "", &args, "http://foobar.com/") + testURIFullURI(t, "", "example.com", "", "", &args, "http://example.com/") // empty scheme and hash - testURIFullURI(t, "", "aa.com", "/foo/bar", "", &args, "http://aa.com/foo/bar") + testURIFullURI(t, "", "example.com", "/foo/bar", "", &args, "http://example.com/foo/bar") // empty hash - testURIFullURI(t, "fTP", "XXx.com", "/foo", "", &args, "ftp://xxx.com/foo") + testURIFullURI(t, "fTP", "example.com", "/foo", "", &args, "ftp://example.com/foo") // empty args - testURIFullURI(t, "https", "xx.com", "/", "aaa", &args, "https://xx.com/#aaa") + testURIFullURI(t, "https", "example.com", "/", "aaa", &args, "https://example.com/#aaa") // non-empty args and non-ASCII path args.Set("foo", "bar") args.Set("xxx", "йух") - testURIFullURI(t, "", "xxx.com", "/тест123", "2er", &args, "http://xxx.com/%D1%82%D0%B5%D1%81%D1%82123?foo=bar&xxx=%D0%B9%D1%83%D1%85#2er") + testURIFullURI(t, "", "example.com", "/тест123", "2er", &args, "http://example.com/%D1%82%D0%B5%D1%81%D1%82123?foo=bar&xxx=%D0%B9%D1%83%D1%85#2er") // test with empty args and non-empty query string var u URI - u.Parse([]byte("google.com"), []byte("/foo?bar=baz&baraz#qqqq")) //nolint:errcheck + u.Parse([]byte("example.com"), []byte("/foo?bar=baz&baraz#qqqq")) //nolint:errcheck uri := u.FullURI() - expectedURI := "http://google.com/foo?bar=baz&baraz#qqqq" + expectedURI := "http://example.com/foo?bar=baz&baraz#qqqq" if string(uri) != expectedURI { t.Fatalf("Unexpected URI: %q. Expected %q", uri, expectedURI) } @@ -278,19 +283,19 @@ func testURIFullURI(t *testing.T, scheme, host, path, hash string, args *Args, e func TestURIParseNilHost(t *testing.T) { t.Parallel() - testURIParseScheme(t, "http://google.com/foo?bar#baz", "http", "google.com", "/foo?bar", "baz") - testURIParseScheme(t, "HTtP://google.com/", "http", "google.com", "/", "") - testURIParseScheme(t, "://google.com/xyz", "http", "google.com", "/xyz", "") - testURIParseScheme(t, "//google.com/foobar", "http", "google.com", "/foobar", "") - testURIParseScheme(t, "fTP://aaa.com", "ftp", "aaa.com", "/", "") - testURIParseScheme(t, "httPS://aaa.com", "https", "aaa.com", "/", "") + testURIParseScheme(t, "http://example.com/foo?bar#baz", "http", "example.com", "/foo?bar", "baz") + testURIParseScheme(t, "HTtP://example.com/", "http", "example.com", "/", "") + testURIParseScheme(t, "://example.com/xyz", "http", "example.com", "/xyz", "") + testURIParseScheme(t, "//example.com/foobar", "http", "example.com", "/foobar", "") + testURIParseScheme(t, "fTP://example.com", "ftp", "example.com", "/", "") + testURIParseScheme(t, "httPS://example.com", "https", "example.com", "/", "") // missing slash after hostname - testURIParseScheme(t, "http://foobar.com?baz=111", "http", "foobar.com", "/?baz=111", "") + testURIParseScheme(t, "http://example.com?baz=111", "http", "example.com", "/?baz=111", "") // slash in args - testURIParseScheme(t, "http://foobar.com?baz=111/222/xyz", "http", "foobar.com", "/?baz=111/222/xyz", "") - testURIParseScheme(t, "http://foobar.com?111/222/xyz", "http", "foobar.com", "/?111/222/xyz", "") + testURIParseScheme(t, "http://example.com?baz=111/222/xyz", "http", "example.com", "/?baz=111/222/xyz", "") + testURIParseScheme(t, "http://example.com?111/222/xyz", "http", "example.com", "/?111/222/xyz", "") } func testURIParseScheme(t *testing.T, uri, expectedScheme, expectedHost, expectedRequestURI, expectedHash string) { @@ -339,54 +344,54 @@ func TestURIParse(t *testing.T) { var u URI // no args - testURIParse(t, &u, "aaa", "sdfdsf", - "http://aaa/sdfdsf", "aaa", "/sdfdsf", "sdfdsf", "", "") + testURIParse(t, &u, "example.com", "sdfdsf", + "http://example.com/sdfdsf", "example.com", "/sdfdsf", "sdfdsf", "", "") // args - testURIParse(t, &u, "xx", "/aa?ss", - "http://xx/aa?ss", "xx", "/aa", "/aa", "ss", "") + testURIParse(t, &u, "example.com", "/aa?ss", + "http://example.com/aa?ss", "example.com", "/aa", "/aa", "ss", "") // args and hash - testURIParse(t, &u, "foobar.com", "/a.b.c?def=gkl#mnop", - "http://foobar.com/a.b.c?def=gkl#mnop", "foobar.com", "/a.b.c", "/a.b.c", "def=gkl", "mnop") + testURIParse(t, &u, "example.com", "/a.b.c?def=gkl#mnop", + "http://example.com/a.b.c?def=gkl#mnop", "example.com", "/a.b.c", "/a.b.c", "def=gkl", "mnop") // '?' and '#' in hash - testURIParse(t, &u, "aaa.com", "/foo#bar?baz=aaa#bbb", - "http://aaa.com/foo#bar?baz=aaa#bbb", "aaa.com", "/foo", "/foo", "", "bar?baz=aaa#bbb") + testURIParse(t, &u, "example.com", "/foo#bar?baz=aaa#bbb", + "http://example.com/foo#bar?baz=aaa#bbb", "example.com", "/foo", "/foo", "", "bar?baz=aaa#bbb") // encoded path - testURIParse(t, &u, "aa.com", "/Test%20+%20%D0%BF%D1%80%D0%B8?asdf=%20%20&s=12#sdf", - "http://aa.com/Test%20+%20%D0%BF%D1%80%D0%B8?asdf=%20%20&s=12#sdf", "aa.com", "/Test + при", "/Test%20+%20%D0%BF%D1%80%D0%B8", "asdf=%20%20&s=12", "sdf") + testURIParse(t, &u, "example.com", "/Test%20+%20%D0%BF%D1%80%D0%B8?asdf=%20%20&s=12#sdf", + "http://example.com/Test%20+%20%D0%BF%D1%80%D0%B8?asdf=%20%20&s=12#sdf", "example.com", "/Test + при", "/Test%20+%20%D0%BF%D1%80%D0%B8", "asdf=%20%20&s=12", "sdf") // host in uppercase - testURIParse(t, &u, "FOObar.COM", "/bC?De=F#Gh", - "http://foobar.com/bC?De=F#Gh", "foobar.com", "/bC", "/bC", "De=F", "Gh") + testURIParse(t, &u, "example.com", "/bC?De=F#Gh", + "http://example.com/bC?De=F#Gh", "example.com", "/bC", "/bC", "De=F", "Gh") // uri with hostname - testURIParse(t, &u, "xxx.com", "http://aaa.com/foo/bar?baz=aaa#ddd", - "http://aaa.com/foo/bar?baz=aaa#ddd", "aaa.com", "/foo/bar", "/foo/bar", "baz=aaa", "ddd") - testURIParse(t, &u, "xxx.com", "https://ab.com/f/b%20r?baz=aaa#ddd", - "https://ab.com/f/b%20r?baz=aaa#ddd", "ab.com", "/f/b r", "/f/b%20r", "baz=aaa", "ddd") + testURIParse(t, &u, "example.com", "http://example.com/foo/bar?baz=aaa#ddd", + "http://example.com/foo/bar?baz=aaa#ddd", "example.com", "/foo/bar", "/foo/bar", "baz=aaa", "ddd") + testURIParse(t, &u, "example.net", "https://example.com/f/b%20r?baz=aaa#ddd", + "https://example.com/f/b%20r?baz=aaa#ddd", "example.com", "/f/b r", "/f/b%20r", "baz=aaa", "ddd") // no slash after hostname in uri - testURIParse(t, &u, "aaa.com", "http://google.com", - "http://google.com/", "google.com", "/", "/", "", "") + testURIParse(t, &u, "example.com", "http://example.com", + "http://example.com/", "example.com", "/", "/", "", "") // uppercase hostname in uri - testURIParse(t, &u, "abc.com", "http://GoGLE.com/aaa", - "http://gogle.com/aaa", "gogle.com", "/aaa", "/aaa", "", "") + testURIParse(t, &u, "example.net", "http://EXAMPLE.COM/aaa", + "http://example.com/aaa", "example.com", "/aaa", "/aaa", "", "") // http:// in query params - testURIParse(t, &u, "aaa.com", "/foo?bar=http://google.com", - "http://aaa.com/foo?bar=http://google.com", "aaa.com", "/foo", "/foo", "bar=http://google.com", "") + testURIParse(t, &u, "example.com", "/foo?bar=http://example.org", + "http://example.com/foo?bar=http://example.org", "example.com", "/foo", "/foo", "bar=http://example.org", "") - testURIParse(t, &u, "aaa.com", "//relative", - "http://aaa.com/relative", "aaa.com", "/relative", "//relative", "", "") + testURIParse(t, &u, "example.com", "//relative", + "http://example.com/relative", "example.com", "/relative", "//relative", "", "") - testURIParse(t, &u, "", "//aaa.com//absolute", - "http://aaa.com/absolute", "aaa.com", "/absolute", "//absolute", "", "") + testURIParse(t, &u, "", "//example.com//absolute", + "http://example.com/absolute", "example.com", "/absolute", "//absolute", "", "") - testURIParse(t, &u, "", "//aaa.com\r\n\r\nGET x", + testURIParse(t, &u, "", "//example.com\r\n\r\nGET x", "http:///", "", "/", "", "", "") testURIParse(t, &u, "", "http://[fe80::1%25en0]/",