Skip to content

Commit

Permalink
Merge pull request #1 from postprime/trung/add_timeout_to_request
Browse files Browse the repository at this point in the history
Add 3sec as timeout when request HTTP
  • Loading branch information
chunvv authored Jul 29, 2022
2 parents 206e9d3 + 2ca7441 commit 16df086
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion goscraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/url"
"regexp"
"strings"
"time"
)

var (
Expand Down Expand Up @@ -123,7 +124,8 @@ func (scraper *Scraper) getDocument() (*Document, error) {
}
req.Header.Add("User-Agent", "GoScraper")

resp, err := http.DefaultClient.Do(req)
c := http.Client{Timeout: 3 * time.Second}
resp, err := c.Do(req)
if resp != nil {
defer resp.Body.Close()
}
Expand Down

0 comments on commit 16df086

Please sign in to comment.