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

    Greg Brimble | Cloudflare Pages

    01/15/2021, 12:21 PM
    encodeBody
    property on the Response, I think! https://developers.cloudflare.com/workers/runtime-apis/response#properties
  • m

    macedonian

    01/15/2021, 12:23 PM
    Ok, so if I understand this correctly the content will be encoded if I set the Content-Encoding header to either 'gzip' or 'br'. Does that mean that I am responsible for checking the Accept-Encoding header? I was expecting that compression would be handled automatically based on the supported encoding of the client.
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2021, 12:28 PM
    Ah, sorry, I misunderstood. Thought you meant "how can I serve up something that's already brotli/gzip encoded". But instead, you're asking "why doesn't Workers automatically handle compression of the response automatically"?
  • m

    macedonian

    01/15/2021, 12:31 PM
    Correct.
  • m

    macedonian

    01/15/2021, 12:31 PM
    I was expecting Workers to automatically compress responses based on the content-type and accept-encoding header of the client.
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2021, 12:33 PM
    I think because you're responsible for creating the Response from whatever Request you're handling, you're also responsible for setting the
    Content-Encoding
    .
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2021, 12:34 PM
    So, this does work if you just pass in
    new Response('hi', { headers: {'Content-Encoding': 'gzip'}})
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2021, 12:35 PM
    https://cloudflareworkers.com/#9afca5c10591d5432f0aeff57b024f5d:https://tutorial.cloudflareworkers.com/
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2021, 12:36 PM
    Side note: we need a bot for sharing Workers on cloudflareworkers.com
  • m

    macedonian

    01/15/2021, 12:40 PM
    Thank you @User for your assistance again! I did a quick test and this seems to work :).
  • w

    wilbo007

    01/15/2021, 1:06 PM
    wait i did not know this was a thing
  • a

    adaptive

    01/15/2021, 2:05 PM
    How big is the response? Below a threshold it doesn't compress.
  • m

    macedonian

    01/15/2021, 2:06 PM
    That was the issue.. It’s like you read my mind. You’re not, right?
  • m

    macedonian

    01/15/2021, 2:07 PM
    It started working when I added some proper data and the response became larger than the basic tests I was doing.
  • m

    Matt

    01/15/2021, 3:22 PM
    👋 Is there a clean/recommended way to respond to a request, and then fire off some followup requests after?
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2021, 3:22 PM
    https://developer.mozilla.org/en-US/docs/Web/API/ExtendableEvent/waitUntil
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2021, 3:32 PM
    Here's an example: https://cloudflareworkers.com/#7bb03d4294d6f1dd50dd02bc3a78f35f:https://developers.cloudflare.com/
  • m

    Matt

    01/15/2021, 3:45 PM
    Legend, ty!
  • m

    Matt

    01/15/2021, 3:59 PM
    Is there a way to block the logic in
    waitUntil
    until the original response has been sent?
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2021, 4:07 PM
    Not really, I don't think. You could probably do a hacky Promise sleep, but I think you'd be best just calling
    waitUntil
    right before returning the Response in
    respondWith
    . Why is it that you need to wait anyway?
  • m

    Matt

    01/15/2021, 4:09 PM
    Sending messages to Discord in the right order -- my logic in waitUntil is managing to get a message to Discord before the respond to the original request gets there. I'm calling
    waitUntil
    on the last line before the response already :/
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2021, 4:09 PM
    Haha, are we all working on Discord bots right now?
  • m

    Matt

    01/15/2021, 4:10 PM
    I'm working on porting https://developers.cloudflare.com/1.1.1.1/fun-stuff/dns-over-discord to a worker
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2021, 4:10 PM
    Maybe a hacky sleep is the answer, then? Just a 300ms wait or something to let the Response get delivered
  • m

    Matt

    01/15/2021, 4:11 PM
    Oh, can a setTimeout in waitUntil go beyond the 10ms limit for the worker?
  • m

    Matt

    01/15/2021, 4:12 PM
    Oh yup I can't read docs
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2021, 4:12 PM
    https://cloudflareworkers.com/#ee0cdfa67c59f3da9d030acb1cde466e:https://developers.cloudflare.com/
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2021, 4:13 PM
    That'll hold off 3 seconds before making the
    followupRequests
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2021, 4:16 PM
    If it's just a slash command you're working on though, can you not just return the message as a response to the request?
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2021, 4:16 PM
    That's literally what I am coding right now
1...515253...2509Latest