Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions defs/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ func (s *Server) IsUp() bool {
return false
}
defer resp.Body.Close()
b, _ := ioutil.ReadAll(resp.Body)
if len(b) > 0 {
b, err := ioutil.ReadAll(resp.Body)
if err != nil || len(b) > 0 {
log.Debugf("Failed when parsing get IP result: %s", b)
return false
}
// only return online if the ping URL returns nothing and 200
return resp.StatusCode == http.StatusOK
Expand Down
2 changes: 1 addition & 1 deletion speedtest/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/librespeed/speedtest-cli/defs"
"github.com/librespeed/speedtest-cli/report"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2"
)

const (
Expand Down
10 changes: 8 additions & 2 deletions speedtest/speedtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,14 @@ func SpeedTest(c *cli.Context) error {

// get the fastest server's index in the `servers` array
var serverIdx int
for idx, ping := range pingList {
if ping > 0 && ping <= pingList[serverIdx] {
for idx, newPing := range pingList {
oldPing, ok := pingList[serverIdx]

if ok {
if newPing > 0 && newPing <= oldPing {
serverIdx = idx
}
} else {
serverIdx = idx
}
}
Expand Down