Skip to content

Commit

Permalink
Use a default user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
koplas committed Jul 31, 2024
1 parent 257c316 commit 0ab851a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
5 changes: 5 additions & 0 deletions cmd/csaf_aggregator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ func (c *config) httpClient(p *provider) util.Client {
Client: client,
Header: c.ExtraHeader,
}
default:
client = &util.HeaderClient{
Client: client,
Header: http.Header{},
}
}

if c.Verbose {
Expand Down
8 changes: 3 additions & 5 deletions cmd/csaf_checker/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,9 @@ func (p *processor) fullClient() util.Client {
client := util.Client(&hClient)

// Add extra headers.
if len(p.cfg.ExtraHeader) > 0 {
client = &util.HeaderClient{
Client: client,
Header: p.cfg.ExtraHeader,
}
client = &util.HeaderClient{
Client: client,
Header: p.cfg.ExtraHeader,
}

// Add optional URL logging.
Expand Down
8 changes: 3 additions & 5 deletions cmd/csaf_downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,9 @@ func (d *downloader) httpClient() util.Client {
client := util.Client(&hClient)

// Add extra headers.
if len(d.cfg.ExtraHeader) > 0 {
client = &util.HeaderClient{
Client: client,
Header: d.cfg.ExtraHeader,
}
client = &util.HeaderClient{
Client: client,
Header: d.cfg.ExtraHeader,
}

// Add optional URL logging.
Expand Down
8 changes: 3 additions & 5 deletions cmd/csaf_downloader/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,9 @@ func (f *forwarder) httpClient() util.Client {
client := util.Client(&hClient)

// Add extra headers.
if len(f.cfg.ForwardHeader) > 0 {
client = &util.HeaderClient{
Client: client,
Header: f.cfg.ForwardHeader,
}
client = &util.HeaderClient{
Client: client,
Header: f.cfg.ForwardHeader,
}

// Add optional URL logging.
Expand Down
5 changes: 5 additions & 0 deletions util/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func (hc *HeaderClient) Do(req *http.Request) (*http.Response, error) {
req.Header.Add(key, v)
}
}

// Use default user agent if none is set
if userAgent := hc.Header.Get("User-Agent"); userAgent == "" {
req.Header.Add("User-Agent", "csaf-distribution/"+SemVersion)
}
return hc.Client.Do(req)
}

Expand Down

0 comments on commit 0ab851a

Please sign in to comment.