Skip to content

add User-Agent header to requests #31

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

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ var UploadConcurrency = 4
var UploadChunkSize = 32 * 1024 * 1024
var noValidateToken bool

const defaultUserAgent = "go-actions-cache/1.0"

var Log = func(string, ...interface{}) {}

type Blob interface {
Expand Down Expand Up @@ -110,6 +112,7 @@ type Opt struct {
Client *http.Client
Timeout time.Duration
BackoffPool *BackoffPool
UserAgent string
}

func New(token, url string, v2 bool, opt Opt) (*Cache, error) {
Expand Down Expand Up @@ -187,6 +190,9 @@ func optsWithDefaults(opt Opt) Opt {
if opt.BackoffPool == nil {
opt.BackoffPool = defaultBackoffPool
}
if opt.UserAgent == "" {
opt.UserAgent = defaultUserAgent
}
return opt
}

Expand Down Expand Up @@ -495,6 +501,7 @@ func (c *Cache) newRequest(method, url string, body func() io.Reader) *request {
headers: map[string]string{
"Authorization": "Bearer " + c.Token.Raw,
"Accept": "application/json;api-version=6.0-preview.1",
"User-Agent": c.opt.UserAgent,
},
}
}
Expand Down
1 change: 1 addition & 0 deletions cache_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (c *Cache) newRequestV2(url string, body func() io.Reader) *request {
headers: map[string]string{
"Authorization": "Bearer " + c.Token.Raw,
"Content-Type": "application/json",
"User-Agent": c.opt.UserAgent,
},
}
}
Expand Down