Fastly will be at Black Hat 2022, Aug. 10-11! We’d love to connect if you will be there.
Schedule time with us at the show.

Extend Fastly to vary its caching per user-agent: BingBot and GoogleBot and the rest.



  • Hiromasa Kakehashi

    Hi Gulshan,

    I don't see any issues in Varying on a custom header as you do in the code.
    You just need to set the Vary header in the responses. Here is an example:


    if ( req.http.User-Agent ~ "(?i)PATTERN1" ) {
    set req.http.X-UA-Device = "Bot";
    } else if ( req.http.User-Agent ~ "(?i)PATTERN2" ) {
    set req.http.X-UA-Device = "Mobile";
    } else {
    set req.http.X-UA-Device = "Desktop";


    if (beresp.http.Vary) {
    set beresp.http.Vary = beresp.http.Vary "X-UA-Device";
    } else {
    set beresp.http.Vary = "X-UA-Device";
    Comment actions Permalink
  • Gulshan Beejan

    Hi Hiromasa,


    Thanks for your reply. We already have a vcl fetch implemented as per your recommendation. I'll apply these on and see how it goes.


    Appreciate your help!

    Comment actions Permalink

Please sign in to leave a comment.