Hi, would appreciate anyone that can give me a pointer!
I’m using a Worker to proxy AWS S3 requests. This works perfectly, but if I change the script to use Streams then I get an intermittent exception.
My script is not that different from the example on the Using Streams documentation (https://developers.cloudflare.com/workers/learning/using-streams
). Here’s my code:
const hostname = 's3.us-east-2.amazonaws.com'
async function handleRequest(request) {
const url = new URL(request.url);
url.hostname = hostname;
const reqHeaders = new Headers(request.headers);
reqHeaders.delete('X-Version');
const response = await fetch(url, { headers: reqHeaders });
// If not using streams:
// return new Response(response.body, response);
// If using streams:
const { readable, writable } = new TransformStream();
response.body.pipeTo(writable);
return new Response(readable, response);
}
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event.request));
});
Some requests get a Cloudflare 1101 error. Real time logs for the Worker show:
"name": "TypeError",
"message": "Cannot read properties of null (reading 'pipeTo')",
Oddly, if repeating the request then it alternates between HTTP 200
and throwing this exception. What did I do wrong?