Skip to content

Commit

Permalink
Use most appropriate function for checking URL
Browse files Browse the repository at this point in the history
From the http.Get() documentation:

> Caller should close resp.Body when done reading from it.

This was not done previously. Since the body is not needed, http.Head() is more appropriate for this application and it
does not impose the requirement to add additional code to clean up.
  • Loading branch information
per1234 committed Jun 7, 2021
1 parent 539e940 commit 3adc412
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/rule/rulefunction/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ func LibraryPropertiesUrlFieldDeadLink() (result ruleresult.Type, output string)
}

logrus.Tracef("Checking URL: %s", url)
httpResponse, err := http.Get(url)
httpResponse, err := http.Head(url)
if err != nil {
return ruleresult.Fail, err.Error()
}
Expand Down
2 changes: 1 addition & 1 deletion internal/rule/rulefunction/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ func TestLibraryPropertiesUrlFieldDeadLink(t *testing.T) {
testTables := []libraryRuleFunctionTestTable{
{"Unable to load", "InvalidLibraryProperties", ruleresult.NotRun, ""},
{"Not defined", "MissingFields", ruleresult.NotRun, ""},
{"Bad URL", "BadURL", ruleresult.Fail, "^Get \"http://invalid/\": dial tcp: lookup invalid:"},
{"Bad URL", "BadURL", ruleresult.Fail, "^Head \"http://invalid/\": dial tcp: lookup invalid:"},
{"HTTP error 404", "URL404", ruleresult.Fail, "^404 Not Found$"},
{"Good URL", "Recursive", ruleresult.Pass, ""},
}
Expand Down

0 comments on commit 3adc412

Please sign in to comment.