diff --git a/client.go b/client.go index f95fe32f..b6316b86 100644 --- a/client.go +++ b/client.go @@ -1516,21 +1516,6 @@ func (c *Client) roundTrip(r *Request) (resp *Response, err error) { } }() - if r.Headers == nil { - r.Headers = make(http.Header) - } - - for _, f := range r.client.udBeforeRequest { - if err = f(r.client, r); err != nil { - return - } - } - for _, f := range r.client.beforeRequest { - if err = f(r.client, r); err != nil { - return - } - } - // setup trace if r.trace == nil && r.client.trace { r.trace = &clientTrace{} diff --git a/request.go b/request.go index 05ef2fc5..63df395d 100644 --- a/request.go +++ b/request.go @@ -587,6 +587,20 @@ func (r *Request) do() (resp *Response, err error) { }() for { + if r.Headers == nil { + r.Headers = make(http.Header) + } + for _, f := range r.client.udBeforeRequest { + if err = f(r.client, r); err != nil { + return + } + } + for _, f := range r.client.beforeRequest { + if err = f(r.client, r); err != nil { + return + } + } + if r.client.wrappedRoundTrip != nil { resp, err = r.client.wrappedRoundTrip.RoundTrip(r) } else {