File tree 1 file changed +49
-0
lines changed
1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ package httpclient
2
+
3
+ import (
4
+ "errors"
5
+ "fmt"
6
+ "net/url"
7
+ "runtime"
8
+
9
+ "github.com/arduino/arduino-cli/cli/globals"
10
+ "github.com/spf13/viper"
11
+ )
12
+
13
+ // Config is the configuration of the http client
14
+ type Config struct {
15
+ UserAgent string
16
+ Proxy * url.URL
17
+ }
18
+
19
+ // DefaultConfig returns the default http client config
20
+ func DefaultConfig () (* Config , error ) {
21
+ var proxy * url.URL
22
+ var err error
23
+ if viper .IsSet ("network.proxy" ) {
24
+ proxyConfig := viper .GetString ("network.proxy" )
25
+ if proxy , err = url .Parse (proxyConfig ); err != nil {
26
+ return nil , errors .New ("Invalid network.proxy '" + proxyConfig + "': " + err .Error ())
27
+ }
28
+ }
29
+
30
+ return & Config {
31
+ UserAgent : UserAgent (),
32
+ Proxy : proxy ,
33
+ }, nil
34
+ }
35
+
36
+ // UserAgent returns the user agent for the cli http client
37
+ func UserAgent () string {
38
+ subComponent := viper .GetString ("network.user_agent_ext" )
39
+ if subComponent != "" {
40
+ subComponent = " " + subComponent
41
+ }
42
+
43
+ return fmt .Sprintf ("%s/%s%s (%s; %s; %s) Commit:%s" ,
44
+ globals .VersionInfo .Application ,
45
+ globals .VersionInfo .VersionString ,
46
+ subComponent ,
47
+ runtime .GOARCH , runtime .GOOS , runtime .Version (),
48
+ globals .VersionInfo .Commit )
49
+ }
You can’t perform that action at this time.
0 commit comments