Bladeren bron

Add IMGPROXY_ENABLE_DEBUG_HEADERS config for debugging infomation (#509)

Huy Le Viet 4 jaren geleden
bovenliggende
commit
a62b22af69
3 gewijzigde bestanden met toevoegingen van 9 en 0 verwijderingen
  1. 3 0
      config.go
  2. 1 0
      docs/configuration.md
  3. 5 0
      processing_handler.go

+ 3 - 0
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")

+ 1 - 0
docs/configuration.md

@@ -43,6 +43,7 @@ echo $(xxd -g 2 -l 64 -p /dev/random | tr -d '\n')
 * `IMGPROXY_CUSTOM_REQUEST_HEADERS`: <img class='pro-badge' src='assets/pro.svg' alt='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`: <img class='pro-badge' src='assets/pro.svg' alt='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`: <img class='pro-badge' src='assets/pro.svg' alt='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
 

+ 5 - 0
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)