Getting your dream job

Extracting querystring and local variables

This page demonstrates how to extract the query string from the path using the new req.url.qs variable and stash the value in a a new local variable for use later.


  sub vcl_recv {
  #FASTLY recv

    // Return non-image
    if (req.url.path !~ "(?i)\.(?:jpg|png)$" 
      || req.url.path !~ "/images/") {
      return(lookup);
    }

    // Signal to send to IO
    set req.http.X-Fastly-Imageopto-Api = "fastly";

    // Don't alter the request if we're running at 
    // the shield, it has already been rewritten
    if (req.http.Fastly-FF) {
        return (lookup);
    }

    // Declare a local variable for building the new params
    declare local var.qs STRING;
    set var.qs = req.url.qs;
    
  }
                

  //facepug.io/images/a3/pug-job.jpg?crop=660:438&width=660
                
Share this story