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

Improve https get diagnostics, add verbose option

* Implement a logging client and activate it using verbose parameter or option
   in checker and aggregator.

Co-authored-by: Sascha L. Teichmann <sascha.teichmann@intevation.de>
This commit is contained in:
Bernhard E. Reiter 2022-06-02 15:07:55 +02:00 committed by GitHub
parent e4011ea4cc
commit a849ac0d5f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 70 additions and 14 deletions

View file

@ -11,6 +11,7 @@ package util
import (
"context"
"io"
"log"
"net/http"
"net/url"
@ -26,12 +27,47 @@ type Client interface {
PostForm(url string, data url.Values) (*http.Response, error)
}
// LoggingClient is a client that logs called URLs.
type LoggingClient struct {
Client
}
// LimitingClient is a Client implementing rate throttling.
type LimitingClient struct {
Client
Limiter *rate.Limiter
}
// Do implements the respective method of the Client interface.
func (lc *LoggingClient) Do(req *http.Request) (*http.Response, error) {
log.Printf("[DO]: %s\n", req.URL.String())
return lc.Do(req)
}
// Get implements the respective method of the Client interface.
func (lc *LoggingClient) Get(url string) (*http.Response, error) {
log.Printf("[GET]: %s\n", url)
return lc.Client.Get(url)
}
// Head implements the respective method of the Client interface.
func (lc *LoggingClient) Head(url string) (*http.Response, error) {
log.Printf("[HEAD]: %s\n", url)
return lc.Head(url)
}
// Post implements the respective method of the Client interface.
func (lc *LoggingClient) Post(url, contentType string, body io.Reader) (*http.Response, error) {
log.Printf("[POST]: %s\n", url)
return lc.Post(url, contentType, body)
}
// PostForm implements the respective method of the Client interface.
func (lc *LoggingClient) PostForm(url string, data url.Values) (*http.Response, error) {
log.Printf("[POST FORM]: %s\n", url)
return lc.PostForm(url, data)
}
// Do implements the respective method of the Client interface.
func (lc *LimitingClient) Do(req *http.Request) (*http.Response, error) {
lc.Limiter.Wait(context.Background())