mirror of
https://github.com/imgproxy/imgproxy.git
synced 2024-11-24 08:12:38 +02:00
More clear downloading timeout errors; Add image URL to fallback image usage warning
This commit is contained in:
parent
302bf64ea2
commit
56858a3692
@ -1,6 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Change
|
||||||
|
- More clear downloading errors.
|
||||||
|
|
||||||
### Fix
|
### Fix
|
||||||
- Fix ICC profile handling in some cases.
|
- Fix ICC profile handling in some cases.
|
||||||
|
|
||||||
|
18
download.go
18
download.go
@ -4,6 +4,7 @@ import (
|
|||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -100,6 +101,17 @@ func initDownloading() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type httpError interface {
|
||||||
|
Timeout() bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkTimeoutErr(err error) error {
|
||||||
|
if httpErr, ok := err.(httpError); ok && httpErr.Timeout() {
|
||||||
|
return errors.New("The image request timed out")
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func checkDimensions(width, height int) error {
|
func checkDimensions(width, height int) error {
|
||||||
if conf.MaxSrcDimension > 0 && (width > conf.MaxSrcDimension || height > conf.MaxSrcDimension) {
|
if conf.MaxSrcDimension > 0 && (width > conf.MaxSrcDimension || height > conf.MaxSrcDimension) {
|
||||||
return errSourceDimensionsTooBig
|
return errSourceDimensionsTooBig
|
||||||
@ -118,7 +130,7 @@ func checkTypeAndDimensions(r io.Reader) (imageType, error) {
|
|||||||
return imageTypeUnknown, errSourceImageTypeNotSupported
|
return imageTypeUnknown, errSourceImageTypeNotSupported
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return imageTypeUnknown, newUnexpectedError(err.Error(), 0)
|
return imageTypeUnknown, newUnexpectedError(checkTimeoutErr(err).Error(), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
imgtype, imgtypeOk := imageTypes[meta.Format()]
|
imgtype, imgtypeOk := imageTypes[meta.Format()]
|
||||||
@ -153,7 +165,7 @@ func readAndCheckImage(r io.Reader, contentLength int) (*imageData, error) {
|
|||||||
|
|
||||||
if _, err = buf.ReadFrom(r); err != nil {
|
if _, err = buf.ReadFrom(r); err != nil {
|
||||||
cancel()
|
cancel()
|
||||||
return nil, newError(404, err.Error(), msgSourceImageIsUnreachable)
|
return nil, newError(404, checkTimeoutErr(err).Error(), msgSourceImageIsUnreachable)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &imageData{buf.Bytes(), imgtype, cancel}, nil
|
return &imageData{buf.Bytes(), imgtype, cancel}, nil
|
||||||
@ -169,7 +181,7 @@ func requestImage(imageURL string) (*http.Response, error) {
|
|||||||
|
|
||||||
res, err := downloadClient.Do(req)
|
res, err := downloadClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, newError(404, err.Error(), msgSourceImageIsUnreachable).SetUnexpected(conf.ReportDownloadingErrors)
|
return res, newError(404, checkTimeoutErr(err).Error(), msgSourceImageIsUnreachable).SetUnexpected(conf.ReportDownloadingErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode != 200 {
|
if res.StatusCode != 200 {
|
||||||
|
@ -185,7 +185,7 @@ func handleProcessing(reqID string, rw http.ResponseWriter, r *http.Request) {
|
|||||||
reportError(err, r)
|
reportError(err, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
logWarning("Could not load image. Using fallback image: %s", err.Error())
|
logWarning("Could not load image %s. Using fallback image. %s", getImageURL(ctx), err.Error())
|
||||||
ctx = context.WithValue(ctx, imageDataCtxKey, fallbackImage)
|
ctx = context.WithValue(ctx, imageDataCtxKey, fallbackImage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user