Possible to use VCL to issue a redirect if backend is too large for Fastly?


#1

Cheers. This is a slight repost of a question from the Tuning topic, I realized that one way maybe to do what I want involves VCL so I figured I’d ask that specific question here.

My problem: our clients are uploading raw media to an S3 bucket. We’ve now reached the point where some of those objects are > 5GB. Thus, when they access it through Fastly using our s3 rewrite backend, Fastly gets the Content-Length: header, sees it’s bigger than 5GB, and fails with a generic 503.

My proposed solution: use VCL to catch the error condition where the beresp content-length header is > 5GB and, in that case, use vcl_error to deliver a 301 redirect to the client containing the raw backend URL, which they can directly receive. We don’t want to make this the default, because most of our content is small static images where Fastly acceleration is key, but we can’t tell easily at request time how big the object is on our end.

My question: First, is this possible? Second, does it make sense? Third, if yes/yes, what’s my best avenue? Override vcl_error to catch this particular case (if 503, check content-length; depending on answer, put something in deliver which sends the redirect)? Or maybe use vcl_pass to do the length check, if possible? I’m an utter VCL n00b so any pointers appreciated, esp. how I’d do it in Fastly.