Skip to content

Commit

Permalink
Show correct User Agent for IsUp and GetIP
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie committed Jul 15, 2020
1 parent 7063aa4 commit 06859d9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions defs/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ func (s *Server) IsUp() bool {

u, _ := s.GetURL()
u.Path = path.Join(u.Path, s.PingURL)
resp, err := http.Get(u.String())

req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
log.Debugf("Failed when creating HTTP request: %s", err)
return false
}
req.Header.Set("User-Agent", UserAgent)

resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Debugf("Error checking for server status: %s", err)
return false
Expand Down Expand Up @@ -120,7 +128,7 @@ func (s *Server) ICMPPingAndJitter(count int, srcIp, network string) (float64, f
return float64(stats.AvgRtt.Milliseconds()), jitter, nil
}

// ICMPPingAndJitter pings the server via accessing ping URL and calculate the average ping and jitter
// PingAndJitter pings the server via accessing ping URL and calculate the average ping and jitter
func (s *Server) PingAndJitter(count int) (float64, float64, error) {
t := time.Now()
defer func() {
Expand Down Expand Up @@ -388,6 +396,8 @@ func (s *Server) GetIPInfo(distanceUnit string) (*GetIPResult, error) {
log.Debugf("Failed when creating HTTP request: %s", err)
return nil, err
}
req.Header.Set("User-Agent", UserAgent)

resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Debugf("Failed when making HTTP request: %s", err)
Expand Down

0 comments on commit 06859d9

Please sign in to comment.