Search code examples
http-headerscache-control

Multipy usage of Cache-Control header


Is it possible to add more than once the Cache-Control header? What setting will be effective if I see the following headers?

Cache-Control: no-cache, no-store, private
Cache-Control: no-cache

Is setting accumulative?


Solution

  • From RFC 7230, 3.2.2. Field Order:

    A recipient MAY combine multiple header fields with the same field name into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field value to the combined field value in order, separated by a comma.

    This request is treated the same as:

    Cache-Control: no-cache, no-store, private, no-cache
    

    Note that in RFC 7234, 4.2.1. Calculating Freshness Lifetime:

    When there is more than one value present for a given directive (e.g., two Expires header fields, multiple Cache-Control: max-age directives), the directive's value is considered invalid.

    I believe the example you give is valid but, for example:

    Cache-Control: max-age=0
    Cache-Control: max-age=3600
    

    would be invalid.