Skip to content

Commit

Permalink
Merge pull request #297 from Frapschen/use_NewRequestWithContext
Browse files Browse the repository at this point in the history
New a HTTP Request with context
  • Loading branch information
figo authored Dec 12, 2022
2 parents e5f8277 + 0c3bea2 commit 45fe314
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (r *Requester) SetClient(client *http.Client) *Requester {
return r
}

//Add auth on redirect if required.
// Add auth on redirect if required.
func (r *Requester) redirectPolicyFunc(req *http.Request, via []*http.Request) error {
if r.BasicAuth != nil {
req.SetBasicAuth(r.BasicAuth.Username, r.BasicAuth.Password)
Expand Down Expand Up @@ -206,14 +206,14 @@ func (r *Requester) Do(ctx context.Context, ar *APIRequest, responseStruct inter
if err = writer.Close(); err != nil {
return nil, err
}
req, err = http.NewRequest(ar.Method, URL.String(), body)
req, err = http.NewRequestWithContext(ctx, ar.Method, URL.String(), body)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", writer.FormDataContentType())
} else {

req, err = http.NewRequest(ar.Method, URL.String(), ar.Payload)
req, err = http.NewRequestWithContext(ctx, ar.Method, URL.String(), ar.Payload)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 45fe314

Please sign in to comment.