-
Notifications
You must be signed in to change notification settings - Fork 1
fix: replace unreliable httpbin.org with www.aem.live in edge-action fixture #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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}`); | ||
| } | ||
|
|
||
| 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
|
||
| 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
|
||
There was a problem hiding this comment.
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 oncontent-length).