From fe929aae84c97b5dbf162d84b308a148f571e17f 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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/http/client.go b/client/http/client.go index 23a019d06110..faa3e5f9d71b 100644 --- a/client/http/client.go +++ b/client/http/client.go @@ -159,10 +159,11 @@ 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 + newClient := *c + newClient.respHandler = handler return c }