none
Serve different content-type based on Accept header (Verizon Premium)?

    Question

  • Hi there

    I have a server which returns a different response based on the Accept header e.g. if Accept header includes "image/webp", a webp image is served, otherwise a jpg is served.

    We run Varnish at server-level and it does this correctly, as per example below:

    Request (with image/webp in Accept header):

    curl -s -D - -o /dev/null "https://REDACTED/media/tokinoha_bowl-4.jpg?sh=2&fmt=webp,jpg" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"


    Response (webp image served):

    HTTP/2 200 
    date: Wed, 06 Feb 2019 08:25:05 GMT
    content-type: image/webp
    access-control-allow-origin: *
    cache-control: public, s-maxage=31536000, max-age=31536000
    x-frame-options: SAMEORIGIN
    x-xss-protection: 1; mode=block
    x-content-type-options: nosniff
    strict-transport-security: max-age=31536000; includeSubDomains
    vary: Accept-Encoding, Accept-Encoding,Origin
    referrer-policy: strict-origin-when-cross-origin
    accept-ranges: bytes
    content-length: 60028


    Request (without webp in Accept header, expect jpg to be served):

    curl -s -D - -o /dev/null "https://REDACTED/media/tokinoha_bowl-4.jpg?sh=2&fmt=webp,jpg" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/apng,*/*;q=0.8"

    Response:

    HTTP/2 200 
    date: Wed, 06 Feb 2019 08:25:18 GMT
    content-type: image/jpeg
    access-control-allow-origin: *
    cache-control: public, s-maxage=31536000, max-age=31536000
    x-frame-options: SAMEORIGIN
    x-xss-protection: 1; mode=block
    x-content-type-options: nosniff
    strict-transport-security: max-age=31536000; includeSubDomains
    vary: Accept-Encoding, Accept-Encoding,Origin
    referrer-policy: strict-origin-when-cross-origin
    accept-ranges: bytes
    content-length: 166991


    We have the below options in the Rules Engine set up, however whichever content-type is cached first is served on all subsequent requests irrespective of request header.

    Does anyone know of a way to achieve this?

    Thanks in advance!


    • Edited by theanatoki Wednesday, February 6, 2019 8:41 AM formatting
    Wednesday, February 6, 2019 8:39 AM

Answers

  • Thanks Travis

    As it turns out, those rules I entered into the Rules Engine (pictured in screenshot from original post) do indeed work. Seems the propagation to nodes took longer than expected.

    Cheers

    • Marked as answer by theanatoki Sunday, March 17, 2019 7:18 AM
    Sunday, March 17, 2019 7:18 AM

All replies

  • I am unsure if these header checks can occur. According to the Rules Engine documentation about Header Features and Caching Features, there doesnt seem to be a way to check for a the custom value of a header.

    You can disable caching for all of those requests, but that removes a lot of the purpose of a CDN. You can also try to create a support request and see if they are aware of a way to do it

    Thursday, February 21, 2019 10:56 PM
    Moderator
  • Thanks Travis

    As it turns out, those rules I entered into the Rules Engine (pictured in screenshot from original post) do indeed work. Seems the propagation to nodes took longer than expected.

    Cheers

    • Marked as answer by theanatoki Sunday, March 17, 2019 7:18 AM
    Sunday, March 17, 2019 7:18 AM