Skip to content

Commit 1a5174a

Browse files
authored
Merge pull request #31 from tonistiigi/tonistiigi/user-agent
add User-Agent header to requests
2 parents e0bc910 + 317b932 commit 1a5174a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

cache.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ var UploadConcurrency = 4
2727
var UploadChunkSize = 32 * 1024 * 1024
2828
var noValidateToken bool
2929

30+
const defaultUserAgent = "go-actions-cache/1.0"
31+
3032
var Log = func(string, ...interface{}) {}
3133

3234
type Blob interface {
@@ -110,6 +112,7 @@ type Opt struct {
110112
Client *http.Client
111113
Timeout time.Duration
112114
BackoffPool *BackoffPool
115+
UserAgent string
113116
}
114117

115118
func New(token, url string, v2 bool, opt Opt) (*Cache, error) {
@@ -187,6 +190,9 @@ func optsWithDefaults(opt Opt) Opt {
187190
if opt.BackoffPool == nil {
188191
opt.BackoffPool = defaultBackoffPool
189192
}
193+
if opt.UserAgent == "" {
194+
opt.UserAgent = defaultUserAgent
195+
}
190196
return opt
191197
}
192198

@@ -495,6 +501,7 @@ func (c *Cache) newRequest(method, url string, body func() io.Reader) *request {
495501
headers: map[string]string{
496502
"Authorization": "Bearer " + c.Token.Raw,
497503
"Accept": "application/json;api-version=6.0-preview.1",
504+
"User-Agent": c.opt.UserAgent,
498505
},
499506
}
500507
}

cache_v2.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ func (c *Cache) newRequestV2(url string, body func() io.Reader) *request {
185185
headers: map[string]string{
186186
"Authorization": "Bearer " + c.Token.Raw,
187187
"Content-Type": "application/json",
188+
"User-Agent": c.opt.UserAgent,
188189
},
189190
}
190191
}

0 commit comments

Comments
 (0)