miniflare
miniflare copied to clipboard
FR: Please support image resizing
Hi! Thanks for miniflare - life saver 🙏
I'm developing various image resizing APIs for our site, and have a tough time testing the functionality locally because the current behaviour is that requests for image-resizing currently silently pass through to the original image, rather than returning a transformed response.
This FR is about being able to test business logic locally, especially with respect to some of the behaviours of image-resizing (headers, error conditions) which are not documented anywhere that I'm aware of, and can currently only be discovered via wrangler dev or deployment.
An ideal result would be if the miniflare.upstream
property (or similar) could nominate a live zone, to which image-resizing requests would be delegated (to get a live response).
If this 'upstream delegation' is not possible, then it would be good to:
- identify error conditions
- send appropriate response headers
- add extra debug logs or debug response headers:
- that this is emulated behaviour, rather than the product of an actual resize operation
- warning if image-resizing is not activated on the zone
If emulation, rather than delegation were chosen, then I would not expect images to be returned in the same size or quality as live workers would return, but I think 'content-type' is important.
Image resizing response headers (anecdotal)
"cf-bgj": "imgq:0,h2pri",
"cf-resized": "internal=ok/m q=0 n=58 c=10 v=2022.3.3 l=104",
ref: https://github.com/cloudflare/wrangler2/issues/534#issuecomment-1079258053
When the image-resizing string is present in the Via header, it means that it is a request coming from another Worker and should be directed to the origin server https://developers.cloudflare.com/images/image-resizing/resize-with-workers/#prevent-request-loops
"Via": "image-resizing"
Image resizing errors (anecdotal)
# response header
"cf-images": '299 "image too large for AVIF"'
Related: AVIF size limit - Developers / Workers - Cloudflare Community
Response body:
ERROR 9401: Missing or invalid resizing parameters: trim string must contain 4 numbers separated by semicolons (top;right;bottom;left)
Discord thread:
@ptim: Sanity check - should I expect to be able to use image-resizing (via workers) in miniflare if upstream is set to a domain with image-resizing enabled? Drives me crazy that it always falls through to the original image, rather than a resized result, and I'm not sure if that's due to configuration error on my part...
@mrbbot Hey! 👋 Unfortunately, image resizing via the cf property is not supported in Miniflare at the moment. It would be possible to add it though, probably using something like https://www.npmjs.com/package/sharp. Maybe open a GitHub issue?
Hey! 👋 Thanks for the feature request. I think if we were to do this, it would be emulation to keep Miniflare's fully-local promise. I'll ask some people internally about the resizing headers/errors. 👍