From 26c64411ee4c77c5a35d7c7f4a6d43e44220ce65 Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Fri, 8 Mar 2024 22:19:57 -0600 Subject: [PATCH] Add 30 second timeout to Web Archive request call --- helpers.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/helpers.go b/helpers.go index 18ecc76..fcc9f64 100644 --- a/helpers.go +++ b/helpers.go @@ -19,6 +19,7 @@ import ( "regexp" "strconv" "strings" + "time" "git.sr.ht/~emersion/gqlclient" "github.com/99designs/gqlgen/graphql" @@ -614,10 +615,22 @@ func GetDisabledElementsByOrg(ctx context.Context, org *models.Organization) (*C } func ArchiveURLSnapshot(ctx context.Context, orgLink *models.OrgLink) error { - resp, err := http.Get(fmt.Sprintf("https://web.archive.org/save/%s", orgLink.URL)) + httpClient := &http.Client{ + Timeout: time.Duration(30) * time.Second, + } + req, err := http.NewRequest( + "GET", + fmt.Sprintf("https://web.archive.org/save/%s", orgLink.URL), + nil, + ) + if err != nil { + return err + } + resp, err := httpClient.Do(req) if err != nil { return err } + if resp.StatusCode == http.StatusOK && resp.Request.URL.String() != "" { orgLink.ArchiveURL = resp.Request.URL.String() return orgLink.Store(ctx) -- 2.43.0