Skip to content
Permalink
Browse files

IMGPROXY_REPORT_DOWNLOADING_ERRORS config

  • Loading branch information...
DarthSim committed Oct 1, 2019
1 parent cc5d380 commit 0de6fc0aa66e4e59a1ca3b9cfa00534a080947a5
Showing with 15 additions and 9 deletions.
  1. +2 −1 CHANGELOG.md
  2. +4 −0 config.go
  3. +4 −3 docs/configuration.md
  4. +3 −3 download.go
  5. +2 −2 errors.go
@@ -5,7 +5,8 @@
- Reimplemented and more errors-tolerant image size parsing;
- TIFF and BMP support;
- Using Application Default Credentials when `IMGPROXY_USE_GCS` is set to `true` but `IMGPROXY_GCS_KEY` is not set.
**Note:** If you use `IMGPROXY_GCS_KEY`, it's recommended to set `IMGPROXY_USE_GCS` to `true` since it may be required by future versions to enable GCS support.
**Note:** If you use `IMGPROXY_GCS_KEY`, it's recommended to set `IMGPROXY_USE_GCS` to `true` since it may be required by future versions to enable GCS support;
- Setting `IMGPROXY_REPORT_DOWNLOADING_ERRORS` to `false` disables reporting of downloading errors.

## v2.5.0

@@ -204,6 +204,8 @@ type config struct {
SentryEnvironment string
SentryRelease string

ReportDownloadingErrors bool

FreeMemoryInterval int
DownloadBufferSize int
GZipBufferSize int
@@ -230,6 +232,7 @@ var conf = config{
HoneybadgerEnv: "production",
SentryEnvironment: "production",
SentryRelease: fmt.Sprintf("imgproxy/%s", version),
ReportDownloadingErrors: true,
FreeMemoryInterval: 10,
BufferPoolCalibrationThreshold: 1024,
}
@@ -336,6 +339,7 @@ func configure() {
strEnvConfig(&conf.SentryDSN, "IMGPROXY_SENTRY_DSN")
strEnvConfig(&conf.SentryEnvironment, "IMGPROXY_SENTRY_ENVIRONMENT")
strEnvConfig(&conf.SentryRelease, "IMGPROXY_SENTRY_RELEASE")
boolEnvConfig(&conf.ReportDownloadingErrors, "IMGPROXY_REPORT_DOWNLOADING_ERRORS")

intEnvConfig(&conf.FreeMemoryInterval, "IMGPROXY_FREE_MEMORY_INTERVAL")
intEnvConfig(&conf.DownloadBufferSize, "IMGPROXY_DOWNLOAD_BUFFER_SIZE")
@@ -187,10 +187,11 @@ imgproxy can report occurred errors to Bugsnag, Honeybadger and Sentry:
* `IMGPROXY_BUGSNAG_KEY`: Bugsnag API key. When provided, enables error reporting to Bugsnag;
* `IMGPROXY_BUGSNAG_STAGE`: Bugsnag stage to report to. Default: `production`;
* `IMGPROXY_HONEYBADGER_KEY`: Honeybadger API key. When provided, enables error reporting to Honeybadger;
* `IMGPROXY_HONEYBADGER_ENV`: Honeybadger env to report to. Default: `production`.
* `IMGPROXY_HONEYBADGER_ENV`: Honeybadger env to report to. Default: `production`;
* `IMGPROXY_SENTRY_DSN`: Sentry project DSN. When provided, enables error reporting to Sentry;
* `IMGPROXY_SENTRY_ENVIRONMENT`: Sentry environment to report to. Default: `production`.
* `IMGPROXY_SENTRY_RELEASE`: Sentry release to report to. Default: `imgproxy/{imgproxy version}`.
* `IMGPROXY_SENTRY_ENVIRONMENT`: Sentry environment to report to. Default: `production`;
* `IMGPROXY_SENTRY_RELEASE`: Sentry release to report to. Default: `imgproxy/{imgproxy version}`;
* `IMGPROXY_REPORT_DOWNLOADING_ERRORS`: when `true`, imgproxy will report downloading errors. Default: `true`.

## Log

@@ -151,20 +151,20 @@ func readAndCheckImage(r io.Reader, contentLength int) (*imageData, error) {
func requestImage(imageURL string) (*http.Response, error) {
req, err := http.NewRequest("GET", imageURL, nil)
if err != nil {
return nil, newError(404, err.Error(), msgSourceImageIsUnreachable).MarkAsUnexpected()
return nil, newError(404, err.Error(), msgSourceImageIsUnreachable).SetUnexpected(conf.ReportDownloadingErrors)
}

req.Header.Set("User-Agent", conf.UserAgent)

res, err := downloadClient.Do(req)
if err != nil {
return res, newError(404, err.Error(), msgSourceImageIsUnreachable).MarkAsUnexpected()
return res, newError(404, err.Error(), msgSourceImageIsUnreachable).SetUnexpected(conf.ReportDownloadingErrors)
}

if res.StatusCode != 200 {
body, _ := ioutil.ReadAll(res.Body)
msg := fmt.Sprintf("Can't download image; Status: %d; %s", res.StatusCode, string(body))
return res, newError(404, msg, msgSourceImageIsUnreachable).MarkAsUnexpected()
return res, newError(404, msg, msgSourceImageIsUnreachable).SetUnexpected(conf.ReportDownloadingErrors)
}

return res, nil
@@ -31,8 +31,8 @@ func (e *imgproxyError) StackTrace() []uintptr {
return e.stack
}

func (e *imgproxyError) MarkAsUnexpected() *imgproxyError {
e.Unexpected = true
func (e *imgproxyError) SetUnexpected(u bool) *imgproxyError {
e.Unexpected = u
return e
}

0 comments on commit 0de6fc0

Please sign in to comment.
You can’t perform that action at this time.