Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 15 additions & 25 deletions test/fixtures/edge-action/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,35 @@ export async function main(req, context) {
const url = new URL(req.url);
const path = url.pathname;

// CacheOverride API test routes
// CacheOverride API test routes - rely on @adobe/fetch polyfill to register
// backends dynamically rather than requiring them to pre-exist on the Fastly service.
if (path.includes('/cache-override-ttl')) {
// Test: TTL override
const cacheOverride = new CacheOverride('override', { ttl: 3600 });
const backendResponse = await fetch('https://httpbin.org/uuid', {
backend: 'httpbin.org',
cacheOverride,
});
const data = await backendResponse.json();
return new Response(`(${context?.func?.name}) ok: cache-override-ttl ttl=3600 uuid=${data.uuid} – ${backendResponse.status}`);
const backendResponse = await fetch('https://www.aem.live/', { cacheOverride });
const contentLength = backendResponse.headers.get('content-length') || 'unknown';
return new Response(`(${context?.func?.name}) ok: cache-override-ttl ttl=3600 size=${contentLength} – ${backendResponse.status}`);
}

Comment on lines 22 to 27

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

In these CacheOverride routes the backend response body is never consumed/cancelled (unlike the fallback route which calls await backendresponse.text()). Leaving the body unread can keep the underlying stream open and may cause unnecessary resource usage in the edge runtime. Consider draining or cancelling the body after reading headers (or compute the size from the consumed body instead of relying on content-length).

Copilot uses AI. Check for mistakes.
if (path.includes('/cache-override-pass')) {
// Test: Pass mode (no caching)
const cacheOverride = new CacheOverride('pass');
const backendResponse = await fetch('https://httpbin.org/uuid', {
backend: 'httpbin.org',
cacheOverride,
});
const data = await backendResponse.json();
return new Response(`(${context?.func?.name}) ok: cache-override-pass mode=pass uuid=${data.uuid} – ${backendResponse.status}`);
const backendResponse = await fetch('https://www.aem.live/', { cacheOverride });
const contentLength = backendResponse.headers.get('content-length') || 'unknown';
return new Response(`(${context?.func?.name}) ok: cache-override-pass mode=pass size=${contentLength} – ${backendResponse.status}`);
}

if (path.includes('/cache-override-key')) {
// Test: Custom cache key
const cacheOverride = new CacheOverride({ ttl: 300, cacheKey: 'test-key' });
Comment on lines +33 to 38

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

Same as above: the response body isn't drained/cancelled before returning. To avoid holding open streams in the edge runtime, consume or cancel the response body (or derive size from the consumed body).

Copilot uses AI. Check for mistakes.
const backendResponse = await fetch('https://httpbin.org/uuid', {
backend: 'httpbin.org',
cacheOverride,
});
const data = await backendResponse.json();
return new Response(`(${context?.func?.name}) ok: cache-override-key cacheKey=test-key uuid=${data.uuid} – ${backendResponse.status}`);
const backendResponse = await fetch('https://www.aem.live/', { cacheOverride });
const contentLength = backendResponse.headers.get('content-length') || 'unknown';
return new Response(`(${context?.func?.name}) ok: cache-override-key cacheKey=test-key size=${contentLength} – ${backendResponse.status}`);
}

// Original status code test
console.log(req.url, `https://httpbin.org/status/${req.url.split('/').pop()}`);
const backendresponse = await fetch(`https://httpbin.org/status/${req.url.split('/').pop()}`, {
backend: 'httpbin.org',
});
console.log(await backendresponse.text());
// Original status code test - use reliable backend.
console.log(req.url, 'https://www.aem.live/');
const backendresponse = await fetch('https://www.aem.live/');
await backendresponse.text();
return new Response(`(${context?.func?.name}) ok: ${await context.env.HEY} ${await context.env.FOO} – ${backendresponse.status}`);
}
Comment on lines +44 to 49

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

Same issue here: the backend response body is not consumed/cancelled before returning. Consuming or cancelling the body helps ensure connections/streams are released promptly (and would also let you compute size deterministically without depending on the content-length header).

Copilot uses AI. Check for mistakes.
Loading