Serve stale content based on user agent (crawlers)

Comments

3 comments

  • Justin

    I just did a rudimentary test and it looks like it's possible. I created 2 VCL snippets: one for detecting the condition I wanted to serve stale on, and the other for actually serving stale. You'd have to check for req.http.user-agent instead.

    In vcl_recv ``` if (req.http.foo == "bar"){ error 901; }

    ```

    In vcl_error if (obj.status == 901) { if (stale.exists) { return(deliver_stale); } }

  • Gavin Staniforth

    Hmm, and what if the stale doesn't exist? can I then do return (deliver); ? or would I have do somekind of restart?

  • Justin

    By default, it would return(deliver); after the check for stale, so no need to add that explicitly.

    However, there is one thing I missed: when in vcl_error and the status is 901it needs to be changed back to 200 before you return (either from the stale or no-stale condition).

Please sign in to leave a comment.