Skip to content

Commit 5740c20

Browse files
committed
feat(remote): add custom headers to HTTP requests
Signed-off-by: chlins <[email protected]>
1 parent 07d63c7 commit 5740c20

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pkg/backend/remote/client.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"oras.land/oras-go/v2/registry/remote/auth"
2727
"oras.land/oras-go/v2/registry/remote/credentials"
2828
"oras.land/oras-go/v2/registry/remote/retry"
29+
30+
"github.com/modelpack/modctl/pkg/version"
2931
)
3032

3133
type Repository = remote.Repository
@@ -78,10 +80,15 @@ func New(repo string, opts ...Option) (*remote.Repository, error) {
7880
return nil, fmt.Errorf("failed to create credential store: %w", err)
7981
}
8082

83+
// Add custom headers to the request.
84+
header := make(http.Header)
85+
header.Set("User-Agent", fmt.Sprintf("modctl/%s", version.GitVersion))
86+
8187
repository.Client = &auth.Client{
8288
Cache: auth.NewCache(),
8389
Credential: credentials.Credential(credStore),
8490
Client: httpClient,
91+
Header: header,
8592
}
8693

8794
repository.PlainHTTP = client.plainHTTP

0 commit comments

Comments
 (0)