Skip to content

Commit a5d92be

Browse files
authored
fix: use http request with context for client (#372)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 1a88c95 commit a5d92be

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

pkgmgr/package.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Blink Labs Software
1+
// Copyright 2025 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
package pkgmgr
1616

1717
import (
18+
"context"
1819
"errors"
1920
"fmt"
2021
"io"
@@ -921,7 +922,12 @@ func (p *PackageInstallStepFile) install(
921922
}
922923

923924
// Fetch data
924-
resp, err := http.Get(p.Url)
925+
ctx := context.Background()
926+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, p.Url, nil)
927+
if err != nil {
928+
return err
929+
}
930+
resp, err := http.DefaultClient.Do(req)
925931
if err != nil {
926932
return err
927933
}

pkgmgr/registry.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package pkgmgr
1717
import (
1818
"archive/zip"
1919
"bytes"
20+
"context"
2021
"errors"
2122
"fmt"
2223
"io"
@@ -136,7 +137,12 @@ func registryPackagesUrl(cfg Config, validate bool) ([]Package, error) {
136137
cfg.Logger.Info(
137138
"Fetching package registry " + cfg.RegistryUrl,
138139
)
139-
resp, err := http.Get(cfg.RegistryUrl)
140+
ctx := context.Background()
141+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, cfg.RegistryUrl, nil)
142+
if err != nil {
143+
return nil, err
144+
}
145+
resp, err := http.DefaultClient.Do(req)
140146
if err != nil {
141147
return nil, err
142148
}

0 commit comments

Comments
 (0)