aboutsummaryrefslogtreecommitdiff
path: root/client_test.go
diff options
context:
space:
mode:
authorGravatar blanet <bupt_xingxin@163.com> 2021-03-18 04:26:56 +0800
committerGravatar GitHub <noreply@github.com> 2021-03-17 21:26:56 +0100
commit860c345f100436b99c11e0897eb60e0b6fd13bcb (patch)
treea49705e2ddd75ef2550afe6694b8fd0b6ab53c50 /client_test.go
parentImmediateHeaderFlush when no body (#995) (diff)
downloadfasthttp-860c345f100436b99c11e0897eb60e0b6fd13bcb.tar.gz
fasthttp-860c345f100436b99c11e0897eb60e0b6fd13bcb.tar.bz2
fasthttp-860c345f100436b99c11e0897eb60e0b6fd13bcb.zip
Fix unexpected panic when calling Do of a PipelineClient (#997)
* fix: Unexpected panic for PipelineClient PipelineClient would panic when calling `Do` with a nil Response as the second parm This commit fixes the unexpected panic by checking nil first before setting fields for Response * Add tests to ensure nil resp is valid for PipelineClient
Diffstat (limited to 'client_test.go')
-rw-r--r--client_test.go32
1 files changed, 28 insertions, 4 deletions
diff --git a/client_test.go b/client_test.go
index 2fb708b..a6be61e 100644
--- a/client_test.go
+++ b/client_test.go
@@ -305,6 +305,34 @@ func TestClientNilResp(t *testing.T) {
}
}
+func TestPipelineClientNilResp(t *testing.T) {
+ t.Parallel()
+
+ ln := fasthttputil.NewInmemoryListener()
+ s := &Server{
+ Handler: func(ctx *RequestCtx) {
+ },
+ }
+ go s.Serve(ln) //nolint:errcheck
+ c := &PipelineClient{
+ Dial: func(addr string) (net.Conn, error) {
+ return ln.Dial()
+ },
+ }
+ req := AcquireRequest()
+ req.Header.SetMethod(MethodGet)
+ req.SetRequestURI("http://example.com")
+ if err := c.Do(req, nil); err != nil {
+ t.Fatal(err)
+ }
+ if err := c.DoTimeout(req, nil, time.Second); err != nil {
+ t.Fatal(err)
+ }
+ if err := c.DoDeadline(req, nil, time.Now().Add(time.Second)); err != nil {
+ t.Fatal(err)
+ }
+}
+
func TestClientParseConn(t *testing.T) {
t.Parallel()
@@ -337,7 +365,6 @@ func TestClientParseConn(t *testing.T) {
if !regexp.MustCompile(`^127\.0\.0\.1:[0-9]{4,5}$`).MatchString(res.LocalAddr().String()) {
t.Fatalf("res LocalAddr addr match fail: %s, hope match: %s", res.LocalAddr().String(), "^127.0.0.1:[0-9]{4,5}$")
}
-
}
func TestClientPostArgs(t *testing.T) {
@@ -419,7 +446,6 @@ func TestClientRedirectSameSchema(t *testing.T) {
t.Fatalf("HostClient error code response %d", statusCode)
return
}
-
}
func TestClientRedirectClientChangingSchemaHttp2Https(t *testing.T) {
@@ -2601,7 +2627,6 @@ func TestHostClientMaxConnWaitTimeoutError(t *testing.T) {
t.Errorf("unexpected body %q. Expecting %q", body, "abcd")
}
}
-
}()
}
wg.Wait()
@@ -2694,7 +2719,6 @@ func TestHostClientMaxConnWaitTimeoutWithEarlierDeadline(t *testing.T) {
t.Errorf("unexpected body %q. Expecting %q", body, "abcd")
}
}
-
}()
}
wg.Wait()