Skip to content

Commit 06859d9

Browse files
committed
Show correct User Agent for IsUp and GetIP
1 parent 7063aa4 commit 06859d9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

defs/server.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@ func (s *Server) IsUp() bool {
4545

4646
u, _ := s.GetURL()
4747
u.Path = path.Join(u.Path, s.PingURL)
48-
resp, err := http.Get(u.String())
48+
49+
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
50+
if err != nil {
51+
log.Debugf("Failed when creating HTTP request: %s", err)
52+
return false
53+
}
54+
req.Header.Set("User-Agent", UserAgent)
55+
56+
resp, err := http.DefaultClient.Do(req)
4957
if err != nil {
5058
log.Debugf("Error checking for server status: %s", err)
5159
return false
@@ -120,7 +128,7 @@ func (s *Server) ICMPPingAndJitter(count int, srcIp, network string) (float64, f
120128
return float64(stats.AvgRtt.Milliseconds()), jitter, nil
121129
}
122130

123-
// ICMPPingAndJitter pings the server via accessing ping URL and calculate the average ping and jitter
131+
// PingAndJitter pings the server via accessing ping URL and calculate the average ping and jitter
124132
func (s *Server) PingAndJitter(count int) (float64, float64, error) {
125133
t := time.Now()
126134
defer func() {
@@ -388,6 +396,8 @@ func (s *Server) GetIPInfo(distanceUnit string) (*GetIPResult, error) {
388396
log.Debugf("Failed when creating HTTP request: %s", err)
389397
return nil, err
390398
}
399+
req.Header.Set("User-Agent", UserAgent)
400+
391401
resp, err := http.DefaultClient.Do(req)
392402
if err != nil {
393403
log.Debugf("Failed when making HTTP request: %s", err)

0 commit comments

Comments
 (0)