Skip to content

fix: support relative container fetch URLs - #238

Merged
mattjohnsonpint merged 3 commits into
cloudflare:mainfrom
badmuriss:agent/fix-relative-container-fetch
Aug 22, 2026
Merged

fix: support relative container fetch URLs#238
mattjohnsonpint merged 3 commits into
cloudflare:mainfrom
badmuriss:agent/fix-relative-container-fetch

Conversation

@badmuriss

@badmuriss badmuriss commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • resolve relative URL paths against an internal container origin
  • preserve existing behavior for absolute URLs and Request inputs
  • add regression coverage for the relative path documented in the public API
  • publish the fix as a patch release

Why

containerFetch('/api/data') is documented as supported, but the URL overload passed the relative path directly to the Request constructor. Since Request requires an absolute URL when no environment origin exists, the call failed with TypeError: Failed to parse URL from /api/data before reaching the container.

The URL overload now resolves its input against http://container. This supplies the origin required by Request while the existing TCP port fetch continues to route the request to the selected container port.

Fixes #28.

Testing

  • npm run typecheck
  • npm run typecheck:all
  • npm run test:unit
  • npm run lint
  • npm run format:check
  • npx changeset status

I also attempted npm run test. The local integration suite could not start its test containers and timed out in workerd with kj/timer.c++: overloaded: operation timed out, including the existing startup and HTTP fetch cases. The unit regression for this change passes.

@badmuriss
badmuriss marked this pull request as ready for review August 11, 2026 13:05
@badmuriss
badmuriss requested a review from a team as a code owner August 11, 2026 13:05
@pkg-pr-new

pkg-pr-new Bot commented Aug 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@cloudflare/containers@238

commit: 679b95a

Flatten the single-test describe block into the file's existing naming
convention and drop the objectContaining assertion that duplicated the
exact-URL check on the first argument.

Add coverage for a relative URL combined with init and an explicit port,
and a guard asserting absolute URLs are still passed through unchanged,
which is the behavior most at risk from resolving against a base origin.
Relative paths resolve against http://container, so the container sees
Host: container. Routing is unaffected, but applications that validate
the Host header need to allow it or use an absolute URL.
@mattjohnsonpint
mattjohnsonpint force-pushed the agent/fix-relative-container-fetch branch from 3cd0706 to 679b95a Compare August 22, 2026 00:29
@mattjohnsonpint
mattjohnsonpint merged commit acf568f into cloudflare:main Aug 22, 2026
6 checks passed
@mattjohnsonpint

Copy link
Copy Markdown
Contributor

Thanks for your contributions! I added some more tests and some info to the readme to match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Are relative fetch paths actually supported?

2 participants