Geektrader|ForexHistoryData.com
Geektrader|ForexHistoryData.com
CDCloudflare Developers
Created by Gtadictos21 on 1/21/2024 in #workers-help
Change Content-Length for file downloads
To change the Content-Length header in a Cloudflare Worker when serving files from an R2 bucket, you should use a FixedLengthStream to create a stream with a specified length. However, your current code snippet is missing a few steps. Here's how you can modify it: firmwareBin = await env.R2.get(decodeURI(key)); let { readable, writable } = new FixedLengthStream(175104); // You need to create a new Response object with the readable stream // and set the headers you want to modify or keep from the original response. let newHeaders = new Headers(firmwareBin.headers); newHeaders.set('Content-Length', '175104'); // Set the desired Content-Length // Pipe the original body to the writable stream of the FixedLengthStream. await firmwareBin.body.pipeTo(writable); // Return a new Response with the readable stream from the FixedLengthStream // and the new headers. return new Response(readable, { headers: newHeaders, status: firmwareBin.status, statusText: firmwareBin.statusText }); Make sure to replace '175104' with the actual length of the content you want to serve. This code creates a new Response object with the readable stream from the FixedLengthStream and sets the Content-Length header to the desired value. It also preserves the original status and status text from the firmwareBin response.
2 replies
CDCloudflare Developers
Created by 알라 on 1/12/2024 in #general-help
Is it cached without an extension?
Files without an extension are not cached by default (look here, https://developers.cloudflare.com/cache/concepts/default-cache-behavior/) only if you use a custom "Cache Everything" page rule.
3 replies
CDCloudflare Developers
Created by Ben 🥰 on 1/13/2024 in #general-help
scenexe.io (is there any hope left?)
Sad story, but @kian is right. Cloudflare acts as the middleman between a site visitor and the target server. A proxy basically, just a very advanced one that tries to prevent attacks on the destination server and much more. However, if the origin server is gone/down, which is the case here, Cloudflare can't do anything as they can't reach the origin server themselves anymore either. You'd have to talk to the person that runs the origin server.
17 replies