Quellcode durchsuchen

Add CookieJar Support for Cookie Passthrough in Redirects (#1334)

* Add CookieJar Support for Cookie Passthrough in Redirects

* Apply comments
Arman Roomana vor 6 Monaten
Ursprung
Commit
fdcd3be83e
1 geänderte Dateien mit 15 neuen und 1 gelöschten Zeilen
  1. 15 1
      imagedata/download.go

+ 15 - 1
imagedata/download.go

@@ -178,8 +178,22 @@ func BuildImageRequest(ctx context.Context, imageURL string, header http.Header,
 }
 }
 
 
 func SendRequest(req *http.Request) (*http.Response, error) {
 func SendRequest(req *http.Request) (*http.Response, error) {
+	var client *http.Client
+	if req.URL.Scheme == "http" || req.URL.Scheme == "https" {
+		clientCopy := *downloadClient
+
+		jar, err := cookiejar.New(nil)
+		if err != nil {
+			return nil, err
+		}
+		clientCopy.Jar = jar
+		client = &clientCopy
+	} else {
+		client = downloadClient
+	}
+
 	for {
 	for {
-		res, err := downloadClient.Do(req)
+		res, err := client.Do(req)
 		if err == nil {
 		if err == nil {
 			return res, nil
 			return res, nil
 		}
 		}