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 }