Skip to content

Commit b98d700

Browse files
committed
Refactor
Signed-off-by: Abdulbois <abdulbois.tursunov@dsr-corporation.com>
1 parent 7ada368 commit b98d700

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ go.sum: go.mod
115115

116116
test:
117117
URL_LIVENESS_CHECK_ENABLED=false go test -tags=dev -v $(PACKAGES)
118+
go test -v utils/validator/url_liveness_test.go
118119

119120
lint:
120121
golangci-lint run ./... --timeout 5m0s
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,4 @@ func TestURLLivenessCheck(t *testing.T) {
4848

4949
require.True(t, _isLiveURL(u))
5050
}
51-
5251
}

utils/validator/validations.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package validator
1616

1717
import (
18+
"context"
1819
"net/http"
1920
"net/url"
2021
"reflect"
@@ -82,6 +83,7 @@ func _validURL(fl validator.FieldLevel, allowedSchemas ...string) bool {
8283
for _, schema := range allowedSchemas {
8384
if u.Scheme == schema {
8485
isSchemaAllowed = true
86+
8587
break
8688
}
8789
}
@@ -97,9 +99,13 @@ func _isLiveURL(u *url.URL) bool {
9799
if config.DisableURLLivenessCheck {
98100
return true
99101
}
100-
101102
// HEAD request only retrieves headers, not the body
102-
resp, err := httpClient.Head(u.String())
103+
req, err := http.NewRequestWithContext(context.Background(), http.MethodHead, u.String(), nil)
104+
if err != nil {
105+
return false
106+
}
107+
108+
resp, err := httpClient.Do(req)
103109
if err != nil {
104110
return false
105111
}

0 commit comments

Comments
 (0)