Skip to content

Support cf.image transformations in local dev#14221

Merged
edmundhung merged 4 commits into
cloudflare:mainfrom
mglewis:mattl/images-2308-cf-image-local-dev
Jun 15, 2026
Merged

Support cf.image transformations in local dev#14221
edmundhung merged 4 commits into
cloudflare:mainfrom
mglewis:mattl/images-2308-cf-image-local-dev

Conversation

@mglewis

@mglewis mglewis commented Jun 8, 2026

Copy link
Copy Markdown
Member

Fixes IMAGES-2308 and (the ancient) #4385

fetch(url, { cf: { image: { ... } } }) allows workers to take advantage of the longstanding transform via Workers feature to transform images . Prior to this change, this feature is not supported in local wrangler dev - the cf object is dropped and the source image bytes are returned.

We already use Sharp to mock some of the more basic capabilities of the images binding. We are repeating the trick here and using it to resize our images we fetch. After we ship, we'll have much closer parity with production.

Changes

  • Outbound fetches now route through an outbound interceptor worker (a renaming + restructuring of the existing strip-cf-connecting-ip worker). It does the existing CF-Connecting-IP header rewrite and the new cf.image transform, then continues down the chain.
  • When a request features cf.image options, the interceptor fetches the origin image (stamping Via: image-resizing for loop-prevention parity) and hands the bytes to a new Node-side Sharp fetcher (cfImageLocalFetcher) over the existing loopback bridge.
  • Attempts to follow production semantics. We support various fit modes, the format: "json" output shape, the cf-resized header. Only resize, rotate and format are honoured, unsupported options are ignored.

Reviewer considerations

  • The outbound interceptor worker is in the path for all worker outbound fetches. Non-image requests are passed through. I don't see any major problems with this, but worth being aware.
  • stripCfConnectingIp: false has been changed for a toggle on a worker to instead toggling the header strip functionality in our outbound inteceptor worker.
  • Local failures fail open (returning the source image). We don't attempt to replicate any of the "Free Transforms Exceeded" logic that may befall customers running in production.

Testing

New spec (test/plugins/core/cf-image.spec.ts). Sanity-checked end-to-end against a demo worker under a local wrangler dev build vs published wrangler.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: Current behaviour isn't documented.

A picture of a cute animal (not mandatory, but encouraged)

@changeset-bot

changeset-bot Bot commented Jun 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cebfded

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
miniflare Minor
@cloudflare/pages-shared Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch
wrangler Patch
@cloudflare/wrangler-bundler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Jun 8, 2026
@mglewis mglewis force-pushed the mattl/images-2308-cf-image-local-dev branch from a52bd41 to 0698951 Compare June 8, 2026 11:55
@pkg-pr-new

pkg-pr-new Bot commented Jun 8, 2026

Copy link
Copy Markdown
create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@14221

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14221

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@14221

miniflare

npm i https://pkg.pr.new/miniflare@14221

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@14221

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@14221

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@14221

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@14221

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@14221

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@14221

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@14221

wrangler

npm i https://pkg.pr.new/wrangler@14221

commit: cebfded

@mglewis mglewis force-pushed the mattl/images-2308-cf-image-local-dev branch from 0698951 to 7e30de7 Compare June 8, 2026 12:30
@mglewis mglewis force-pushed the mattl/images-2308-cf-image-local-dev branch from 7e30de7 to c01768f Compare June 8, 2026 12:42
@mglewis mglewis marked this pull request as ready for review June 8, 2026 12:43
@mglewis mglewis requested a review from workers-devprod as a code owner June 8, 2026 12:43
@workers-devprod workers-devprod requested review from a team and edmundhung and removed request for a team June 8, 2026 12:43
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/cf-image-local-transforms.md: [@cloudflare/wrangler]
  • packages/miniflare/src/index.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/plugins/core/index.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/plugins/images/fetcher.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/workers/core/constants.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/workers/core/outbound.worker.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/workers/core/strip-cf-connecting-ip.worker.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/workers/images/images.worker.ts: [@cloudflare/wrangler]
  • packages/miniflare/test/plugins/core/cf-image.spec.ts: [@cloudflare/wrangler]

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

Comment thread packages/miniflare/src/plugins/core/index.ts
Comment thread packages/miniflare/src/index.ts
Comment thread packages/miniflare/src/workers/core/outbound.worker.ts Outdated
Comment thread packages/miniflare/src/workers/core/outbound.worker.ts Outdated
Comment thread packages/miniflare/src/plugins/images/fetcher.ts Outdated
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@workers-devprod

workers-devprod commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@edmundhung edmundhung left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Can you address the remaining feedbacks from devin? If they are invalid, just leave a comment and resolve them.

Could you please get a review from your team too?

@workers-devprod workers-devprod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Jun 15, 2026
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@ns476

ns476 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

LGTM from an Images perspective ✅

@edmundhung edmundhung merged commit 0e055d3 into cloudflare:main Jun 15, 2026
55 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants