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

cscli: Add user-agent to all hub requests #2915

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions pkg/cwhub/cwhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,26 @@ import (
"sort"
"strings"
"time"

"github.com/crowdsecurity/go-cs-lib/version"
)

// hubTransport wraps a Transport to set a custom User-Agent.
type hubTransport struct {
Transport http.RoundTripper
}

func (t *hubTransport) RoundTrip(req *http.Request) (*http.Response, error) {
req.Header.Set("User-Agent", "crowdsec/"+version.String())
return t.Transport.RoundTrip(req)
}

// hubClient is the HTTP client used to communicate with the CrowdSec Hub.
var hubClient = &http.Client{
Timeout: 120 * time.Second,
Transport: &hubTransport{
Transport: http.DefaultTransport,
},
}

// safePath returns a joined path and ensures that it does not escape the base directory.
Expand Down