Skip to content

Commit

Permalink
Recreate new client for every req in grid
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikidepia committed Jul 15, 2024
1 parent 7c87d18 commit 48a5d87
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions handlers/grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
scraper "instafix/handlers/scraper"
"io"
"math"
"net"
"net/http"
"os"
"path/filepath"
Expand All @@ -20,15 +19,6 @@ import (
"golang.org/x/image/draw"
)

var transport = &http.Transport{
DialContext: (&net.Dialer{
Timeout: 5 * time.Second,
}).DialContext,
TLSHandshakeTimeout: 5 * time.Second,
ResponseHeaderTimeout: 5 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
DisableKeepAlives: true,
}
var timeout = 60 * time.Second

// getHeight returns the height of the rows, imagesWH [w,h]
Expand Down Expand Up @@ -162,12 +152,12 @@ func Grid(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

var wg sync.WaitGroup
images := make([]image.Image, len(mediaURLs))
client := http.Client{Transport: transport, Timeout: timeout}
for i, mediaURL := range mediaURLs {
wg.Add(1)

go func(i int, url string) {
defer wg.Done()
client := http.Client{Timeout: timeout}
req, err := http.NewRequest(http.MethodGet, url, http.NoBody)
if err != nil {
return
Expand Down

0 comments on commit 48a5d87

Please sign in to comment.