https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • d

    dave

    02/14/2023, 2:45 PM
    and the
    { cf: { lol: true }}
    part isn't spoofable?
  • k

    kian

    02/14/2023, 2:45 PM
    Copy code
    ts
    export default <ExportedHandler> {
      fetch(req) {
        return Response.json(req.cf);
      }
    }
    Copy code
    ts
    interface Environment {
      FOO: Fetcher
    }
    
    export default <ExportedHandler<Environment>> {
      fetch(req, env) {
        return env.FOO.fetch(req.url, { cf: { lol: true }})
      }
    }
    Output:
    Copy code
    json
    {"lol":true}
  • k

    kian

    02/14/2023, 2:48 PM
    req.cf
    is populated on the inbound request by Cloudflare - and since Service Bindings don't 'go through' Cloudflare's normal request flow, it'll only exist on the Worker you're invoking if you pass it yourself
  • k

    kian

    02/14/2023, 2:48 PM
    Even then, custom properties would also only ever be yourself
  • d

    dave

    02/14/2023, 2:49 PM
    thanks!
  • o

    o0th

    02/14/2023, 3:14 PM
    Hello everyone, is there any difference in
    wrangler.toml
    for this two routes?
    Copy code
    routes = [
      { pattern = "*/something/*", zone_id = "xxx" },
      { pattern = "domain.com/*/something/*", zone_name = "domain.com" }
    ]
    Because I cannot use
    zone_id
    for the second and
    zone_name
    for the first while publishing my worker 😦
  • t

    Tomleads

    02/14/2023, 3:33 PM
    pages-action worked a treat by the way. Thank you 🙂
  • e

    Erisa | Support Engineer

    02/14/2023, 3:33 PM
    No prob! happy to help
  • z

    zelnaut

    02/14/2023, 3:55 PM
    Hi, I'm wondering how feasible it would be to use a Worker to stream a file to R2, while also compressing it on the fly (preferably with zstd or deflate). I could chunk the input into same-size parts, but the compressed chunks would be different sizes, meaning I couldn't use multi-part uploads. Same issue with using a
    TransformStream
    , I wouldn't know the file size ahead of time. Anyone have any ideas/suggestions?
  • k

    kian

    02/14/2023, 3:57 PM
    Eeeh - it’s not ideal to do in Workers since as you’ve mentioned, size must be known upfront or have consistent parts
  • k

    kian

    02/14/2023, 3:58 PM
    How big are the files in question?
  • z

    zelnaut

    02/14/2023, 3:59 PM
    Range of file sizes, largest would be somewhere between 5-10 GBs
  • k

    kian

    02/14/2023, 3:59 PM
    Anything above 5GB would have to be multipart anyhow - and those sizes rule out buffering
  • k

    kian

    02/14/2023, 4:00 PM
    I’d be impressed if a Worker could compress those within CPU limits - but I’ve never tested the efficiency of CompressionStream
  • d

    dave

    02/14/2023, 4:26 PM
    Is there any problem you see that would cause a race condition? I sometimes get an error on the fetch at the end saying that
    This ReadableStream is disturbed (has already been read from), and cannot be used as a body.
    .
    Copy code
    typescript
            let request_body = request.body;
    
            if(request_body && !cleaned_headers.has("X-Amz-Content-Sha256")) {
                let hash_body;
                [request_body, hash_body] = request_body.tee();
                const digestStream = new crypto.DigestStream("SHA-256");
                hash_body.pipeTo(digestStream);
                const digest = await digestStream.digest; // This could be a problem for bundled usage
                const hexString = [...new Uint8Array(digest)].map(b => b.toString(16).padStart(2, '0')).join('')
                cleaned_headers.set("X-Amz-Content-Sha256", hexString)
            }
    
    
            const lambdaResponse = await aws.fetch(target_url, {
                method: request.method,
                headers: cleaned_headers,
                body: request_body,
                redirect: "manual"
            })
  • d

    dave

    02/14/2023, 4:28 PM
    https://github.com/mhart/aws4fetch/blob/f245b426987aa7e622b0dd5315ae82da274f30bd/src/main.js#L101
  • d

    dave

    02/14/2023, 4:28 PM
    oh hmm
  • d

    dave

    02/14/2023, 4:44 PM
    this race condition is so weird
  • d

    dave

    02/14/2023, 4:51 PM
    Am I not setting
    request_body
    correctly?
  • d

    dave

    02/14/2023, 4:58 PM
    I am so confused.
  • d

    dave

    02/14/2023, 5:00 PM
    well, I have up to 128MB of memory...
  • d

    dave

    02/14/2023, 5:00 PM
    I guess I can just buffer it all in
  • k

    kian

    02/14/2023, 5:06 PM
    weird scoping issue with request_body being outside the if block and reassigned inside?
  • k

    kian

    02/14/2023, 5:06 PM
    totally random guess, not at a PC to test anything
  • k

    kian

    02/14/2023, 5:07 PM
    that error sounds like the underlying ReadableStream source is being used rather than one of the two streams from tee
  • d

    dave

    02/14/2023, 5:08 PM
    yeah, beginning to think it might be aws4fetch related
  • d

    dave

    02/14/2023, 5:08 PM
    my max body size is 6MB anyway iirc
  • d

    dave

    02/14/2023, 5:08 PM
    so I can buffer it in
  • n

    Nosh

    02/14/2023, 9:44 PM
    Do I need to add DNS records if I am creating custom worker routes?
  • e

    Erisa | Support Engineer

    02/14/2023, 9:45 PM
    custom domains? no
1...227022712272...2509Latest