Skip to content
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

Fix so that HTTP request don't wait for responses indefinitely #506

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add test case that fails to create new request
  • Loading branch information
torao committed Nov 24, 2022
commit 42fcf13ce27e799738b5be196523a8d12ffb44a1
2 changes: 1 addition & 1 deletion libs/net/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// HttpGet sends a GET request to the specified url with timeout and return the response.
func HttpGet(url string, timeout time.Duration) (*http.Response, error) {
request, err := http.NewRequestWithContext(context.Background(), "GET", url, nil)
request, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
if err != nil {
return nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions libs/net/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ func TestHttpGetWithTimeout(t *testing.T) {
require.InDeltaf(t, timeout.Seconds(), delta, accuracy,
"response time of %.3f sec exceeded +%d%% of the expected timeout of %.3f sec", delta, uint(accuracy*100), timeout.Seconds())
}

func TestHttpGetWithInvalidURL(t *testing.T) {
_, err := HttpGet("\n", 0*time.Second)
require.Error(t, err)
}