Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Golang - Handle nil header request #873

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading