Skip to content

Commit

Permalink
Use http.NewRequestWithContext directly. (#185)
Browse files Browse the repository at this point in the history
Directly set the context instead of (implicitly) setting `context.Background` and then do a copy with the intended context.
  • Loading branch information
Necoro authored May 30, 2022
1 parent 2d63bb4 commit 7c163b1
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,10 @@ func (f *Parser) ParseURL(feedURL string) (feed *Feed, err error) {
func (f *Parser) ParseURLWithContext(feedURL string, ctx context.Context) (feed *Feed, err error) {
client := f.httpClient()

req, err := http.NewRequest("GET", feedURL, nil)
req, err := http.NewRequestWithContext(ctx, "GET", feedURL, nil)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
req.Header.Set("User-Agent", f.UserAgent)

if f.AuthConfig != nil && f.AuthConfig.Username != "" && f.AuthConfig.Password != "" {
Expand Down

0 comments on commit 7c163b1

Please sign in to comment.