Skip to content

Commit

Permalink
for 200-400, and fix reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
hyorigo committed Jul 22, 2024
1 parent f6bca22 commit 7e5e9ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/net/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ func httpPingFunc(ctx context.Context, url string, timeout time.Duration) (time.
// create a http client with timeout and tracing
client := &http.Client{
Timeout: timeout,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse // do not follow redirects
},

Check warning on line 79 in lib/net/ping.go

View check run for this annotation

Codecov / codecov/patch

lib/net/ping.go#L78-L79

Added lines #L78 - L79 were not covered by tests
Transport: &http.Transport{
DisableKeepAlives: true,
},
}
req, err := http.NewRequestWithContext(httptrace.WithClientTrace(ctx, trace), "GET", url, nil)
if err != nil {
Expand All @@ -86,7 +92,7 @@ func httpPingFunc(ctx context.Context, url string, timeout time.Duration) (time.
return 0, err
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
if resp.StatusCode < 200 || resp.StatusCode >= 400 {
return 0, fmt.Errorf("unacceptable status: %d", resp.StatusCode)
}

Check warning on line 97 in lib/net/ping.go

View check run for this annotation

Codecov / codecov/patch

lib/net/ping.go#L96-L97

Added lines #L96 - L97 were not covered by tests
return connDur, nil
Expand Down
2 changes: 2 additions & 0 deletions lib/net/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func TestLoadModule_Ping(t *testing.T) {
print(s)
assert.eq(s.total, 4)
assert.true(s.success > 0)
assert.true(s.min > 0)
`),
},
{
Expand All @@ -111,6 +112,7 @@ func TestLoadModule_Ping(t *testing.T) {
print(s)
assert.eq(s.total, 10)
assert.true(s.success > 0)
assert.true(s.min > 0)
`),
},
{
Expand Down

0 comments on commit 7e5e9ce

Please sign in to comment.