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) {