|
@@ -14,8 +14,11 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
var (
|
|
var (
|
|
- downloadClient *http.Client
|
|
|
|
- imageDataCtxKey = ctxKey("imageData")
|
|
|
|
|
|
+ downloadClient *http.Client
|
|
|
|
+
|
|
|
|
+ imageDataCtxKey = ctxKey("imageData")
|
|
|
|
+ cacheControlHeaderCtxKey = ctxKey("cacheControlHeader")
|
|
|
|
+ expiresHeaderCtxKey = ctxKey("expiresHeader")
|
|
|
|
|
|
errSourceDimensionsTooBig = newError(422, "Source image dimensions are too big", "Invalid source image")
|
|
errSourceDimensionsTooBig = newError(422, "Source image dimensions are too big", "Invalid source image")
|
|
errSourceResolutionTooBig = newError(422, "Source image resolution is too big", "Invalid source image")
|
|
errSourceResolutionTooBig = newError(422, "Source image resolution is too big", "Invalid source image")
|
|
@@ -196,6 +199,8 @@ func downloadImage(ctx context.Context) (context.Context, context.CancelFunc, er
|
|
}
|
|
}
|
|
|
|
|
|
ctx = context.WithValue(ctx, imageDataCtxKey, imgdata)
|
|
ctx = context.WithValue(ctx, imageDataCtxKey, imgdata)
|
|
|
|
+ ctx = context.WithValue(ctx, cacheControlHeaderCtxKey, res.Header.Get("Cache-Control"))
|
|
|
|
+ ctx = context.WithValue(ctx, expiresHeaderCtxKey, res.Header.Get("Expires"))
|
|
|
|
|
|
return ctx, imgdata.Close, err
|
|
return ctx, imgdata.Close, err
|
|
}
|
|
}
|
|
@@ -203,3 +208,11 @@ func downloadImage(ctx context.Context) (context.Context, context.CancelFunc, er
|
|
func getImageData(ctx context.Context) *imageData {
|
|
func getImageData(ctx context.Context) *imageData {
|
|
return ctx.Value(imageDataCtxKey).(*imageData)
|
|
return ctx.Value(imageDataCtxKey).(*imageData)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func getCacheControlHeader(ctx context.Context) string {
|
|
|
|
+ return ctx.Value(cacheControlHeaderCtxKey).(string)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func getExpiresHeader(ctx context.Context) string {
|
|
|
|
+ return ctx.Value(expiresHeaderCtxKey).(string)
|
|
|
|
+}
|