Skip to content

Commit 0bafbaa

Browse files
committed
fix: add a timeout to builtin HTTP functions
Signed-off-by: Grant Linville <[email protected]>
1 parent 6e73e5c commit 0bafbaa

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkg/builtin/builtin.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"path/filepath"
1515
"sort"
1616
"strings"
17+
"time"
1718

1819
"github.com/BurntSushi/locker"
1920
"github.com/gptscript-ai/gptscript/pkg/types"
@@ -336,8 +337,10 @@ func SysHTTPGet(ctx context.Context, env []string, input string) (_ string, err
336337
return "", err
337338
}
338339

340+
c := http.Client{Timeout: 10 * time.Second}
341+
339342
log.Debugf("http get %s", params.URL)
340-
resp, err := http.Get(params.URL)
343+
resp, err := c.Get(params.URL)
341344
if err != nil {
342345
return "", err
343346
}
@@ -387,7 +390,9 @@ func SysHTTPPost(ctx context.Context, env []string, input string) (_ string, err
387390
req.Header.Set("Content-Type", params.ContentType)
388391
}
389392

390-
resp, err := http.DefaultClient.Do(req)
393+
c := http.Client{Timeout: 10 * time.Second}
394+
395+
resp, err := c.Do(req)
391396
if err != nil {
392397
return "", err
393398
}

0 commit comments

Comments
 (0)