Skip to content

Commit 3adc412

Browse files
committed
Use most appropriate function for checking URL
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.
1 parent 539e940 commit 3adc412

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

internal/rule/rulefunction/library.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ func LibraryPropertiesUrlFieldDeadLink() (result ruleresult.Type, output string)
10111011
}
10121012

10131013
logrus.Tracef("Checking URL: %s", url)
1014-
httpResponse, err := http.Get(url)
1014+
httpResponse, err := http.Head(url)
10151015
if err != nil {
10161016
return ruleresult.Fail, err.Error()
10171017
}

internal/rule/rulefunction/library_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ func TestLibraryPropertiesUrlFieldDeadLink(t *testing.T) {
751751
testTables := []libraryRuleFunctionTestTable{
752752
{"Unable to load", "InvalidLibraryProperties", ruleresult.NotRun, ""},
753753
{"Not defined", "MissingFields", ruleresult.NotRun, ""},
754-
{"Bad URL", "BadURL", ruleresult.Fail, "^Get \"http://invalid/\": dial tcp: lookup invalid:"},
754+
{"Bad URL", "BadURL", ruleresult.Fail, "^Head \"http://invalid/\": dial tcp: lookup invalid:"},
755755
{"HTTP error 404", "URL404", ruleresult.Fail, "^404 Not Found$"},
756756
{"Good URL", "Recursive", ruleresult.Pass, ""},
757757
}

0 commit comments

Comments
 (0)