diff --git a/config.go b/config.go index 4214cb6f..f95b402d 100644 --- a/config.go +++ b/config.go @@ -267,6 +267,8 @@ type config struct { ReportDownloadingErrors bool + EnableDebugHeaders bool + FreeMemoryInterval int DownloadBufferSize int GZipBufferSize int @@ -430,6 +432,7 @@ func configure() error { strEnvConfig(&conf.SentryEnvironment, "IMGPROXY_SENTRY_ENVIRONMENT") strEnvConfig(&conf.SentryRelease, "IMGPROXY_SENTRY_RELEASE") boolEnvConfig(&conf.ReportDownloadingErrors, "IMGPROXY_REPORT_DOWNLOADING_ERRORS") + boolEnvConfig(&conf.EnableDebugHeaders, "IMGPROXY_ENABLE_DEBUG_HEADERS") intEnvConfig(&conf.FreeMemoryInterval, "IMGPROXY_FREE_MEMORY_INTERVAL") intEnvConfig(&conf.DownloadBufferSize, "IMGPROXY_DOWNLOAD_BUFFER_SIZE") diff --git a/docs/configuration.md b/docs/configuration.md index 5e056bfc..516de476 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -43,6 +43,7 @@ echo $(xxd -g 2 -l 64 -p /dev/random | tr -d '\n') * `IMGPROXY_CUSTOM_REQUEST_HEADERS`: pro list of custom headers that imgproxy will send while requesting the source image, divided by `\;` (can be redefined by `IMGPROXY_CUSTOM_HEADERS_SEPARATOR`). Example: `X-MyHeader1=Lorem\;X-MyHeader2=Ipsum`; * `IMGPROXY_CUSTOM_RESPONSE_HEADERS`: pro list of custom response headers, divided by `\;` (can be redefined by `IMGPROXY_CUSTOM_HEADERS_SEPARATOR`). Example: `X-MyHeader1=Lorem\;X-MyHeader2=Ipsum`; * `IMGPROXY_CUSTOM_HEADERS_SEPARATOR`: pro string that will be used as a custom headers separator. Default: `\;`; +* `IMGPROXY_ENABLE_DEBUG_HEADERS`: when `true`, imgproxy will add `X-Origin-Content-Length` header with the value is size of the source image. Default: `false`. ## Security diff --git a/processing_handler.go b/processing_handler.go index f85c89dc..e118e135 100644 --- a/processing_handler.go +++ b/processing_handler.go @@ -111,6 +111,11 @@ func respondWithImage(ctx context.Context, reqID string, r *http.Request, rw htt rw.Write(data) } + if conf.EnableDebugHeaders { + imgdata := getImageData(ctx) + rw.Header().Set("X-Origin-Content-Length", strconv.Itoa(len(imgdata.Data))) + } + imageURL := getImageURL(ctx) logResponse(reqID, r, 200, nil, &imageURL, po)