mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Add User Agent to image download reqs (#1222)
This commit is contained in:
@@ -2,6 +2,7 @@ package utils
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@@ -33,6 +34,10 @@ func ProcessImageInput(imageInput string) ([]byte, error) {
|
||||
// ReadImageFromURL returns image data from a URL
|
||||
func ReadImageFromURL(url string) ([]byte, error) {
|
||||
client := &http.Client{
|
||||
Transport: &http.Transport{ // ignore insecure certificates
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
|
||||
Timeout: imageGetTimeout,
|
||||
}
|
||||
|
||||
@@ -47,6 +52,7 @@ func ReadImageFromURL(url string) ([]byte, error) {
|
||||
if req.URL.Scheme != "" {
|
||||
req.Header.Set("Referer", req.URL.Scheme+"://"+req.Host+"/")
|
||||
}
|
||||
req.Header.Set("User-Agent", GetUserAgent())
|
||||
|
||||
resp, err := client.Do(req)
|
||||
|
||||
@@ -54,6 +60,10 @@ func ReadImageFromURL(url string) ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode >= 400 {
|
||||
return nil, fmt.Errorf("http error %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
|
||||
Reference in New Issue
Block a user