1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00

feat: log redirects (#458)

* feat: log redirects

* improved logging and renamed function
This commit is contained in:
cintek 2023-09-26 10:03:09 +02:00 committed by GitHub
parent 0c9516ac08
commit 49da14d47f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -92,10 +92,26 @@ func (d *downloader) addStats(o *stats) {
d.stats.add(o) d.stats.add(o)
} }
// logRedirect logs redirects of the http client.
func logRedirect(req *http.Request, via []*http.Request) error {
vs := make([]string, len(via))
for i, v := range via {
vs[i] = v.URL.String()
}
slog.Debug("Redirecting",
"to", req.URL.String(),
"via", strings.Join(vs, " -> "))
return nil
}
func (d *downloader) httpClient() util.Client { func (d *downloader) httpClient() util.Client {
hClient := http.Client{} hClient := http.Client{}
if d.cfg.LogLevel.slogLevel() <= slog.LevelDebug {
hClient.CheckRedirect = logRedirect
}
var tlsConfig tls.Config var tlsConfig tls.Config
if d.cfg.Insecure { if d.cfg.Insecure {
tlsConfig.InsecureSkipVerify = true tlsConfig.InsecureSkipVerify = true