From b90b5bf2dc84c90bf08a94e711233ee6046332c2 Mon Sep 17 00:00:00 2001 From: adnano Date: Sun, 21 Feb 2021 09:40:31 -0500 Subject: [PATCH] client: Copy only what is needed from the Request --- client.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/client.go b/client.go index b194c40..9d79832 100644 --- a/client.go +++ b/client.go @@ -74,15 +74,16 @@ func (c *Client) Do(ctx context.Context, req *Request) (*Response, error) { if host != punycode { host = punycode - // Make a copy of the request - r2 := new(Request) - *r2 = *req - r2.URL = new(url.URL) - *r2.URL = *req.URL - req = r2 + // Copy the URL and update the host + u := new(url.URL) + *u = *req.URL + u.Host = net.JoinHostPort(host, port) - // Set the host - req.URL.Host = net.JoinHostPort(host, port) + // Use the new URL in the request so that the server gets + // the punycoded hostname + req = &Request{ + URL: u, + } } // Use request host if provided