Skip to content

Commit dc9ea74

Browse files
committed
refactor: use head
1 parent c1201b4 commit dc9ea74

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎api/request.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ func (r *Request) Get(path string) (*Response, error) {
114114
return r.Send(http.MethodGet, path)
115115
}
116116

117+
func (r *Request) Head(path string) (*Response, error) {
118+
return r.Send(http.MethodHead, path)
119+
}
120+
117121
func (r *Request) Post(path string) (*Response, error) {
118122
return r.Send(http.MethodPost, path)
119123
}

‎cmd/pro/livescan/fetch.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@ var fetchCmd = &cobra.Command{
5252
responseURL := api.PrefixedPath(fmt.Sprintf("/livescan/%s/response/%s/", scannerId, fileHash))
5353
downloadURL := api.PrefixedPath(fmt.Sprintf("/livescan/%s/download/%s/", scannerId, fileHash))
5454

55-
resp, err := client.NewRequest().Get(responseURL)
55+
resp, err := client.NewRequest().Head(downloadURL)
5656
var url string
5757
switch {
58-
case err == nil && resp.IsSuccess():
59-
url = responseURL
60-
case resp != nil && resp.Response != nil && resp.StatusCode == http.StatusNotFound:
58+
case resp != nil && resp.Response != nil && resp.IsSuccess():
6159
url = downloadURL
60+
case resp != nil && resp.Response != nil && resp.StatusCode == http.StatusNotFound:
61+
url = responseURL
6262
default:
6363
if err != nil {
6464
return err
6565
}
66-
return fmt.Errorf("unexpected error fetching %q", responseURL)
66+
return fmt.Errorf("unexpected error fetching %q", downloadURL)
6767
}
6868

6969
opts := utils.NewDownloadOptions(

0 commit comments

Comments
 (0)