Skip to content

Commit

Permalink
make sure beforeRequests executed before client middleware(fix #248)
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Jun 28, 2023
1 parent 45ace4b commit d9fef28
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
15 changes: 0 additions & 15 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
14 changes: 14 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d9fef28

Please sign in to comment.