Skip to content

Commit 712e2a7

Browse files
committed
upgrade downloader to v2 with httpclient injection
1 parent 039d07d commit 712e2a7

File tree

9 files changed

+23
-27
lines changed

9 files changed

+23
-27
lines changed

arduino/cores/packagemanager/download.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"fmt"
2020

2121
"github.com/arduino/arduino-cli/arduino/cores"
22-
"go.bug.st/downloader"
22+
"go.bug.st/downloader/v2"
2323
semver "go.bug.st/relaxed-semver"
2424
)
2525

arduino/libraries/librariesmanager/download.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package librariesmanager
1818
import (
1919
"net/url"
2020

21-
"go.bug.st/downloader"
21+
"go.bug.st/downloader/v2"
2222
)
2323

2424
// LibraryIndexURL is the URL where to get library index.

arduino/resources/helpers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"os"
2121

2222
"github.com/arduino/go-paths-helper"
23-
"go.bug.st/downloader"
23+
"go.bug.st/downloader/v2"
2424
)
2525

2626
// ArchivePath returns the path of the Archive of the specified DownloadResource relative

arduino/resources/helpers_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ import (
2323
"strings"
2424
"testing"
2525

26+
"github.com/arduino/arduino-cli/httpclient"
2627
"github.com/arduino/go-paths-helper"
2728
"github.com/stretchr/testify/require"
28-
"go.bug.st/downloader"
29+
"go.bug.st/downloader/v2"
2930
)
3031

3132
type EchoHandler struct{}
@@ -53,7 +54,9 @@ func TestDownloadApplyUserAgentHeaderUsingConfig(t *testing.T) {
5354
URL: srv.URL,
5455
}
5556

56-
d, err := r.Download(tmp, &downloader.Config{RequestHeaders: http.Header{"User-Agent": []string{goldUserAgentValue}}})
57+
httpClient := httpclient.NewWithConfig(&httpclient.Config{UserAgent: goldUserAgentValue})
58+
59+
d, err := r.Download(tmp, &downloader.Config{HttpClient: *httpClient})
5760
require.NoError(t, err)
5861
err = d.Run()
5962
require.NoError(t, err)

arduino/resources/resources_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
"github.com/arduino/go-paths-helper"
2424
"github.com/stretchr/testify/require"
25-
"go.bug.st/downloader"
25+
"go.bug.st/downloader/v2"
2626
)
2727

2828
func TestDownloadAndChecksums(t *testing.T) {

commands/download.go

+8-17
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,24 @@
1616
package commands
1717

1818
import (
19-
"net/http"
20-
"net/url"
2119
"time"
2220

2321
"github.com/arduino/arduino-cli/httpclient"
2422
rpc "github.com/arduino/arduino-cli/rpc/commands"
25-
"github.com/pkg/errors"
26-
"github.com/sirupsen/logrus"
27-
"github.com/spf13/viper"
28-
"go.bug.st/downloader"
23+
"go.bug.st/downloader/v2"
2924
)
3025

3126
// GetDownloaderConfig returns the downloader configuration based on
3227
// current settings.
3328
func GetDownloaderConfig() (*downloader.Config, error) {
34-
res := &downloader.Config{
35-
RequestHeaders: http.Header{
36-
"User-Agent": []string{httpclient.UserAgent()},
37-
},
29+
30+
httpClient, err := httpclient.New()
31+
if err != nil {
32+
return nil, err
3833
}
39-
if viper.IsSet("network.proxy") {
40-
proxy := viper.GetString("network.proxy")
41-
if _, err := url.Parse(proxy); err != nil {
42-
return nil, errors.New("Invalid network.proxy '" + proxy + "': " + err.Error())
43-
}
44-
res.ProxyURL = proxy
45-
logrus.Infof("Using proxy %s", proxy)
34+
35+
res := &downloader.Config{
36+
HttpClient: *httpClient,
4637
}
4738
return res, nil
4839
}

commands/instances.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
paths "github.com/arduino/go-paths-helper"
3434
"github.com/sirupsen/logrus"
3535
"github.com/spf13/viper"
36-
"go.bug.st/downloader"
36+
"go.bug.st/downloader/v2"
3737
)
3838

3939
// this map contains all the running Arduino Core Services instances

go.mod

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ require (
3838
github.com/spf13/viper v1.6.2
3939
github.com/stretchr/testify v1.4.0
4040
go.bug.st/cleanup v1.0.0
41-
go.bug.st/downloader v1.2.0
41+
go.bug.st/downloader/v2 v2.0.1
4242
go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18
4343
go.bug.st/serial v1.0.0
4444
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 // indirect
@@ -51,3 +51,5 @@ require (
5151
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
5252
gopkg.in/yaml.v2 v2.2.4
5353
)
54+
55+
replace go.bug.st/downloader/v2 v2.0.1 => github.com/hdiniz/go-downloader/v2 v2.0.1

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ github.com/h2non/filetype v1.0.8 h1:le8gpf+FQA0/DlDABbtisA1KiTS0Xi+YSC/E8yY3Y14=
8585
github.com/h2non/filetype v1.0.8/go.mod h1:isekKqOuhMj+s/7r3rIeTErIRy4Rub5uBWHfvMusLMU=
8686
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
8787
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
88+
github.com/hdiniz/go-downloader/v2 v2.0.1 h1:8+yB5gwlJJSri5wPatCuCDb3dnFDMROiLGQfb7fbFBA=
89+
github.com/hdiniz/go-downloader/v2 v2.0.1/go.mod h1:VZW2V1iGKV8rJL2ZEGIDzzBeKowYv34AedJz13RzVII=
8890
github.com/imjasonmiller/godice v0.1.2 h1:T1/sW/HoDzFeuwzOOuQjmeMELz9CzZ53I2CnD+08zD4=
8991
github.com/imjasonmiller/godice v0.1.2/go.mod h1:8cTkdnVI+NglU2d6sv+ilYcNaJ5VSTBwvMbFULJd/QQ=
9092
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
@@ -205,8 +207,6 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q
205207
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
206208
go.bug.st/cleanup v1.0.0 h1:XVj1HZxkBXeq3gMT7ijWUpHyIC1j8XAoNSyQ06CskgA=
207209
go.bug.st/cleanup v1.0.0/go.mod h1:EqVmTg2IBk4znLbPD28xne3abjsJftMdqqJEjhn70bk=
208-
go.bug.st/downloader v1.2.0 h1:YmXFTcTnm0v8WzAWHn2DyV46c/Izlc/gReXubc2oBho=
209-
go.bug.st/downloader v1.2.0/go.mod h1:l+RPbNbrTB+MoAIp8nrZsP22nRPDy26XJZQqmm4gNT4=
210210
go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18 h1:F1qxtaFuewctYc/SsHRn+Q7Dtwi+yJGPgVq8YLtQz98=
211211
go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18/go.mod h1:Cx1VqMtEhE9pIkEyUj3LVVVPkv89dgW8aCKrRPDR/uE=
212212
go.bug.st/serial v1.0.0 h1:ogEPzrllCsnG00EqKRjeYvPRsO7NJW6DqykzkdD6E/k=

0 commit comments

Comments
 (0)