mirror of
https://github.com/go-task/task.git
synced 2025-11-23 22:24:45 +02:00
feat: use timeout in RemoteExists function
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package taskfile
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -43,7 +44,7 @@ var (
|
||||
// at the given URL with any of the default Taskfile files names. If any of
|
||||
// these match a file, the first matching path will be returned. If no files are
|
||||
// found, an error will be returned.
|
||||
func RemoteExists(l *logger.Logger, u *url.URL) (*url.URL, error) {
|
||||
func RemoteExists(ctx context.Context, l *logger.Logger, u *url.URL) (*url.URL, error) {
|
||||
// Create a new HEAD request for the given URL to check if the resource exists
|
||||
req, err := http.NewRequest("HEAD", u.String(), nil)
|
||||
if err != nil {
|
||||
@@ -51,7 +52,7 @@ func RemoteExists(l *logger.Logger, u *url.URL) (*url.URL, error) {
|
||||
}
|
||||
|
||||
// Request the given URL
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
resp, err := http.DefaultClient.Do(req.WithContext(ctx))
|
||||
if err != nil {
|
||||
return nil, errors.TaskfileFetchFailedError{URI: u.String()}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user