From cd5397a13ff0faff4a34a5e4f3d5a7313861fcb9 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Tue, 21 Nov 2023 13:39:47 +0800 Subject: [PATCH] Copy a new client inside WithRespHandler Signed-off-by: JmPotato --- client/http/client.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/http/client.go b/client/http/client.go index 23a019d0611..5e438a77076 100644 --- a/client/http/client.go +++ b/client/http/client.go @@ -159,11 +159,12 @@ func (c *client) Close() { log.Info("[pd] http client closed") } -// WithRespHandler sets the client with the given HTTP response handler. +// WithRespHandler sets and returns a new client with the given HTTP response handler. // This allows the caller to customize how the response is handled, including error handling logic. func (c *client) WithRespHandler(handler func(resp *http.Response) error) Client { - c.respHandler = handler - return c + newClient := *c + newClient.respHandler = handler + return &newClient } func (c *client) reqCounter(name, status string) {