mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-09-28 12:37:47 +02:00
use "clean" HTTP transport; Use context for downloading timeout control
This commit is contained in:
@@ -70,7 +70,7 @@ func loadWatermark() (err error) {
|
||||
}
|
||||
|
||||
if len(config.WatermarkURL) > 0 {
|
||||
Watermark, err = Download(config.WatermarkURL, "watermark", DownloadOptions{Header: nil, CookieJar: nil}, security.DefaultOptions())
|
||||
Watermark, err = Download(context.Background(), config.WatermarkURL, "watermark", DownloadOptions{Header: nil, CookieJar: nil}, security.DefaultOptions())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func loadFallbackImage() (err error) {
|
||||
case len(config.FallbackImagePath) > 0:
|
||||
FallbackImage, err = FromFile(config.FallbackImagePath, "fallback image", security.DefaultOptions())
|
||||
case len(config.FallbackImageURL) > 0:
|
||||
FallbackImage, err = Download(config.FallbackImageURL, "fallback image", DownloadOptions{Header: nil, CookieJar: nil}, security.DefaultOptions())
|
||||
FallbackImage, err = Download(context.Background(), config.FallbackImageURL, "fallback image", DownloadOptions{Header: nil, CookieJar: nil}, security.DefaultOptions())
|
||||
default:
|
||||
FallbackImage, err = nil, nil
|
||||
}
|
||||
@@ -130,8 +130,8 @@ func FromFile(path, desc string, secopts security.Options) (*ImageData, error) {
|
||||
return imgdata, nil
|
||||
}
|
||||
|
||||
func Download(imageURL, desc string, opts DownloadOptions, secopts security.Options) (*ImageData, error) {
|
||||
imgdata, err := download(imageURL, opts, secopts)
|
||||
func Download(ctx context.Context, imageURL, desc string, opts DownloadOptions, secopts security.Options) (*ImageData, error) {
|
||||
imgdata, err := download(ctx, imageURL, opts, secopts)
|
||||
if err != nil {
|
||||
if nmErr, ok := err.(*ErrorNotModified); ok {
|
||||
nmErr.Message = fmt.Sprintf("Can't download %s: %s", desc, nmErr.Message)
|
||||
|
Reference in New Issue
Block a user