Skip to content

add cli httpclient with support for proxy configuration #672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 19, 2020
Prev Previous commit
Next Next commit
use cli httpclient on board list command
  • Loading branch information
hdiniz committed Apr 23, 2020
commit 5424e22257db85ac23675b003cb786caf4a28ed6
11 changes: 8 additions & 3 deletions commands/board/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"regexp"
"sync"

"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/httpclient"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/pkg/errors"
"github.com/segmentio/stats/v4"
Expand All @@ -51,12 +51,17 @@ func apiByVidPid(vid, pid string) ([]*rpc.BoardListItem, error) {
url := fmt.Sprintf("%s/%s/%s", vidPidURL, vid, pid)
retVal := []*rpc.BoardListItem{}
req, _ := http.NewRequest("GET", url, nil)
req.Header = globals.NewHTTPClientHeader("")
req.Header.Set("Content-Type", "application/json")

// TODO: use proxy if set

if res, err := http.DefaultClient.Do(req); err == nil {
httpClient, err := httpclient.New()

if err != nil {
return nil, errors.Wrap(err, "failed to initialize http client")
}

if res, err := httpClient.Do(req); err == nil {
if res.StatusCode >= 400 {
if res.StatusCode == 404 {
return nil, ErrNotFound
Expand Down