Skip to content

Commit

Permalink
Merge pull request #873 from SSWConsulting/handle-nil-header-request
Browse files Browse the repository at this point in the history
Golang - Handle nil header request
  • Loading branch information
tombui99 authored Apr 22, 2024
2 parents 664f389 + 0b7150a commit d99032a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions docker/sswlinkauditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ func getClient() *http.Client {
}

func addClientHeaders(r *http.Request) {
r.Header.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36")
r.Header.Set("Cache-Control", "no-cache")
r.Header.Set("Connection", "keep-alive")
r.Header.Set("Accept-Encoding", "*")
if r != nil {
r.Header.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36")
r.Header.Set("Cache-Control", "no-cache")
r.Header.Set("Connection", "keep-alive")
r.Header.Set("Accept-Encoding", "*")
}
}

func check(link Link, linkch chan LinkStatus, number int) {
Expand All @@ -78,8 +80,10 @@ func check(link Link, linkch chan LinkStatus, number int) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
r, e := http.NewRequestWithContext(ctx, "GET", link.url, nil)
addClientHeaders(r)
r.Header.Add("Accept", "*/*")
if r != nil {
addClientHeaders(r)
r.Header.Add("Accept", "*/*")
}
dnsErr := new(net.DNSError)

if e != nil {
Expand Down

0 comments on commit d99032a

Please sign in to comment.