diff options
author | Erik Dubbelboer <erik@dubbelboer.com> | 2020-05-18 18:30:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-18 18:30:29 +0200 |
commit | d22782d3f7e73d9bbe3efab53722e9be45708e9e (patch) | |
tree | f8809ffc68d40de398f7518c4e784330db479d82 /client_test.go | |
parent | Make FS return a redirect for directories without trailing slash (#802) (diff) | |
parent | HostClient can't switch between protocols (diff) | |
download | fasthttp-d22782d3f7e73d9bbe3efab53722e9be45708e9e.tar.gz fasthttp-d22782d3f7e73d9bbe3efab53722e9be45708e9e.tar.bz2 fasthttp-d22782d3f7e73d9bbe3efab53722e9be45708e9e.zip |
HostClient can't switch between protocols (#800)
Diffstat (limited to 'client_test.go')
-rw-r--r-- | client_test.go | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/client_test.go b/client_test.go index 9b5fafc..5166afd 100644 --- a/client_test.go +++ b/client_test.go @@ -245,7 +245,7 @@ func TestClientRedirectSameSchema(t *testing.T) { urlParsed, err := url.Parse(destURL) if err != nil { - fmt.Println(err) + t.Fatal(err) return } @@ -270,7 +270,7 @@ func TestClientRedirectSameSchema(t *testing.T) { } -func TestClientRedirectChangingSchemaHttp2Https(t *testing.T) { +func TestClientRedirectClientChangingSchemaHttp2Https(t *testing.T) { t.Parallel() listenHTTPS := testClientRedirectListener(t, true) @@ -287,14 +287,7 @@ func TestClientRedirectChangingSchemaHttp2Https(t *testing.T) { destURL := fmt.Sprintf("http://%s/baz", listenHTTP.Addr().String()) - urlParsed, err := url.Parse(destURL) - if err != nil { - fmt.Println(err) - return - } - - reqClient := &HostClient{ - Addr: urlParsed.Host, + reqClient := &Client{ TLSConfig: &tls.Config{ InsecureSkipVerify: true, }, @@ -312,6 +305,42 @@ func TestClientRedirectChangingSchemaHttp2Https(t *testing.T) { } } +func TestClientRedirectHostClientChangingSchemaHttp2Https(t *testing.T) { + t.Parallel() + + listenHTTPS := testClientRedirectListener(t, true) + defer listenHTTPS.Close() + + listenHTTP := testClientRedirectListener(t, false) + defer listenHTTP.Close() + + sHTTPS := testClientRedirectChangingSchemaServer(t, listenHTTPS, listenHTTP, true) + defer sHTTPS.Stop() + + sHTTP := testClientRedirectChangingSchemaServer(t, listenHTTPS, listenHTTP, false) + defer sHTTP.Stop() + + destURL := fmt.Sprintf("http://%s/baz", listenHTTP.Addr().String()) + + urlParsed, err := url.Parse(destURL) + if err != nil { + t.Fatal(err) + return + } + + reqClient := &HostClient{ + Addr: urlParsed.Host, + TLSConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + } + + _, _, err = reqClient.GetTimeout(nil, destURL, 4000*time.Millisecond) + if err != ErrHostClientRedirectToDifferentScheme { + t.Fatal("expected HostClient error") + } +} + func testClientRedirectListener(t *testing.T, isTLS bool) net.Listener { var ln net.Listener var err error |