Forum Discussion

Jean-Christoph6's avatar
Jean-Christoph6
Icon for Nimbostratus rankNimbostratus
Aug 14, 2012

How to configure the cache to handle the Vary Header ?

Hi There,

 

 

We have a JBOSS server that serves tons of XML documents via HTTP REST Requests.

 

The tricky thing is that the content of the answers (XML documents) provided to the clients depends from the Accept and Accept-Language HTTP Headers value that was passed to the server by the client.

 

 

One quick example should help to clarify:

 

 

 

The URL http://192.168.1.1/docs/DOC_1 with the two headers= ‘Accept: notice=object’ and 'Accept-Language: eng' returns an XML document of type Notice=Object in english

 

but the same URL

 

http://192.168.1.1/docs/DOC_1 with the two headers= ‘Accept: notice=branch’ and 'Accept-Language: eng' returns an XML document of type Notice=branch in english

 

 

To help the cache module to serve the right content to the clients, the JBOSS needs to add the following Header in its HTTP Responses: “Vary: Accept,Accept-Language”

 

Unfortunately, it seems that the Web Accelerator module doesn’t take in account this Vary Header and may serve the wrong content to the client (the branch notice instead of the object notice or vice-versa)…

 

 

Any ideas how to configure the WAM to handle correctly the Vary Header ?

 

 

Many thanks in advance.

 

  • Make sure that the content being served is matching to the XML node in the WebAccelerator policy. XML pages should be matching to the XML node in the library policy. The default settings on this node is for WebAccelerator to not cache the content. If the default settings have been changed the variation rules need to be used to ensure that content is cached appropriately. In your example you would need to add a variation rule for the Accept header. The default is that all headers serve the same content and in this case the Accept:notice header needs to be defined to serve different content.

     

     

    From the policy select acceleration rules

     

    Select Variation rules

     

    From the "Add Parameter" dropdown select Header

     

    Click Add

     

    In the Name box enter "Accept"

     

    Under Value Groups select "different content" from the drop down

     

    Save

     

    Publish
  • Hi Dwan,

     

     

    Many thanks for this tip. It works perfectly.

     

    Furthermore, the usage of Vary header is useless with this config.

     

     

    JC
  • Glad that worked. Yes the Vary header is very particular. Many browsers only recognize the vary= accept-encoding header. Any other vary header makes content uncacheable by the browser.