From 0b7150ab63cede8ad20dc47d0dbc6c2dac9055a5 Mon Sep 17 00:00:00 2001 From: tombui99 Date: Mon, 22 Apr 2024 15:04:58 +1000 Subject: [PATCH] Handle nil header request --- docker/sswlinkauditor.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/docker/sswlinkauditor.go b/docker/sswlinkauditor.go index c7f60607..ae16e847 100644 --- a/docker/sswlinkauditor.go +++ b/docker/sswlinkauditor.go @@ -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) { @@ -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 {