idnits 2.17.1 draft-ietf-httpbis-cache-06.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == The document seems to contain a disclaimer for pre-RFC5378 work, but was first submitted on or after 10 November 2008. The disclaimer is usually necessary only for documents that revise or obsolete older RFCs, and that take significant amounts of text from those RFCs. If you can contact all authors of the source material and they are willing to grant the BCP78 rights to the IETF Trust, you can and should remove the disclaimer. Otherwise, the disclaimer is needed and you can ignore this comment. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (November 4, 2019) is 1625 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Unused Reference: 'RFC3986' is defined on line 1560, but no explicit reference was found in the text == Unused Reference: 'RFC7234' is defined on line 1604, but no explicit reference was found in the text == Outdated reference: A later version (-19) exists of draft-ietf-httpbis-messaging-06 -- Possible downref: Normative reference to a draft: ref. 'Messaging' == Outdated reference: A later version (-19) exists of draft-ietf-httpbis-semantics-06 -- Possible downref: Normative reference to a draft: ref. 'Semantics' -- Possible downref: Non-RFC (?) normative reference: ref. 'USASCII' -- Obsolete informational reference (is this intentional?): RFC 2616 (Obsoleted by RFC 7230, RFC 7231, RFC 7232, RFC 7233, RFC 7234, RFC 7235) -- Obsolete informational reference (is this intentional?): RFC 7234 (Obsoleted by RFC 9111) Summary: 0 errors (**), 0 flaws (~~), 6 warnings (==), 7 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 HTTP Working Group R. Fielding, Ed. 3 Internet-Draft Adobe 4 Obsoletes: 7234 (if approved) M. Nottingham, Ed. 5 Intended status: Standards Track Fastly 6 Expires: May 7, 2020 J. Reschke, Ed. 7 greenbytes 8 November 4, 2019 10 HTTP Caching 11 draft-ietf-httpbis-cache-06 13 Abstract 15 The Hypertext Transfer Protocol (HTTP) is a stateless application- 16 level protocol for distributed, collaborative, hypertext information 17 systems. This document defines HTTP caches and the associated header 18 fields that control cache behavior or indicate cacheable response 19 messages. 21 This document obsoletes RFC 7234. 23 Editorial Note 25 This note is to be removed before publishing as an RFC. 27 Discussion of this draft takes place on the HTTP working group 28 mailing list (ietf-http-wg@w3.org), which is archived at 29 . 31 Working Group information can be found at ; 32 source code and issues list for this draft can be found at 33 . 35 The changes in this draft are summarized in Appendix C.7. 37 Status of This Memo 39 This Internet-Draft is submitted in full conformance with the 40 provisions of BCP 78 and BCP 79. 42 Internet-Drafts are working documents of the Internet Engineering 43 Task Force (IETF). Note that other groups may also distribute 44 working documents as Internet-Drafts. The list of current Internet- 45 Drafts is at https://datatracker.ietf.org/drafts/current/. 47 Internet-Drafts are draft documents valid for a maximum of six months 48 and may be updated, replaced, or obsoleted by other documents at any 49 time. It is inappropriate to use Internet-Drafts as reference 50 material or to cite them other than as "work in progress." 52 This Internet-Draft will expire on May 7, 2020. 54 Copyright Notice 56 Copyright (c) 2019 IETF Trust and the persons identified as the 57 document authors. All rights reserved. 59 This document is subject to BCP 78 and the IETF Trust's Legal 60 Provisions Relating to IETF Documents 61 (https://trustee.ietf.org/license-info) in effect on the date of 62 publication of this document. Please review these documents 63 carefully, as they describe your rights and restrictions with respect 64 to this document. Code Components extracted from this document must 65 include Simplified BSD License text as described in Section 4.e of 66 the Trust Legal Provisions and are provided without warranty as 67 described in the Simplified BSD License. 69 This document may contain material from IETF Documents or IETF 70 Contributions published or made publicly available before November 71 10, 2008. The person(s) controlling the copyright in some of this 72 material may not have granted the IETF Trust the right to allow 73 modifications of such material outside the IETF Standards Process. 74 Without obtaining an adequate license from the person(s) controlling 75 the copyright in such materials, this document may not be modified 76 outside the IETF Standards Process, and derivative works of it may 77 not be created outside the IETF Standards Process, except to format 78 it for publication as an RFC or to translate it into languages other 79 than English. 81 Table of Contents 83 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 84 1.1. Requirements Notation . . . . . . . . . . . . . . . . . . 5 85 1.2. Syntax Notation . . . . . . . . . . . . . . . . . . . . . 5 86 1.3. Delta Seconds . . . . . . . . . . . . . . . . . . . . . . 6 87 2. Overview of Cache Operation . . . . . . . . . . . . . . . . . 6 88 3. Storing Responses in Caches . . . . . . . . . . . . . . . . . 7 89 3.1. Storing Incomplete Responses . . . . . . . . . . . . . . 8 90 3.2. Storing Responses to Authenticated Requests . . . . . . . 9 91 3.3. Combining Partial Content . . . . . . . . . . . . . . . . 9 92 4. Constructing Responses from Caches . . . . . . . . . . . . . 9 93 4.1. Calculating Cache Keys with Vary . . . . . . . . . . . . 10 94 4.2. Freshness . . . . . . . . . . . . . . . . . . . . . . . . 12 95 4.2.1. Calculating Freshness Lifetime . . . . . . . . . . . 13 96 4.2.2. Calculating Heuristic Freshness . . . . . . . . . . . 14 97 4.2.3. Calculating Age . . . . . . . . . . . . . . . . . . . 14 98 4.2.4. Serving Stale Responses . . . . . . . . . . . . . . . 16 99 4.3. Validation . . . . . . . . . . . . . . . . . . . . . . . 16 100 4.3.1. Sending a Validation Request . . . . . . . . . . . . 16 101 4.3.2. Handling a Received Validation Request . . . . . . . 17 102 4.3.3. Handling a Validation Response . . . . . . . . . . . 19 103 4.3.4. Freshening Stored Responses upon Validation . . . . . 19 104 4.3.5. Freshening Responses with HEAD . . . . . . . . . . . 20 105 4.4. Invalidation . . . . . . . . . . . . . . . . . . . . . . 20 106 5. Header Field Definitions . . . . . . . . . . . . . . . . . . 21 107 5.1. Age . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 108 5.2. Cache-Control . . . . . . . . . . . . . . . . . . . . . . 22 109 5.2.1. Request Cache-Control Directives . . . . . . . . . . 23 110 5.2.1.1. max-age . . . . . . . . . . . . . . . . . . . . . 23 111 5.2.1.2. max-stale . . . . . . . . . . . . . . . . . . . . 23 112 5.2.1.3. min-fresh . . . . . . . . . . . . . . . . . . . . 24 113 5.2.1.4. no-cache . . . . . . . . . . . . . . . . . . . . 24 114 5.2.1.5. no-store . . . . . . . . . . . . . . . . . . . . 24 115 5.2.1.6. no-transform . . . . . . . . . . . . . . . . . . 25 116 5.2.1.7. only-if-cached . . . . . . . . . . . . . . . . . 25 117 5.2.2. Response Cache-Control Directives . . . . . . . . . . 25 118 5.2.2.1. must-revalidate . . . . . . . . . . . . . . . . . 25 119 5.2.2.2. no-cache . . . . . . . . . . . . . . . . . . . . 26 120 5.2.2.3. no-store . . . . . . . . . . . . . . . . . . . . 26 121 5.2.2.4. no-transform . . . . . . . . . . . . . . . . . . 27 122 5.2.2.5. public . . . . . . . . . . . . . . . . . . . . . 27 123 5.2.2.6. private . . . . . . . . . . . . . . . . . . . . . 27 124 5.2.2.7. proxy-revalidate . . . . . . . . . . . . . . . . 28 125 5.2.2.8. max-age . . . . . . . . . . . . . . . . . . . . . 28 126 5.2.2.9. s-maxage . . . . . . . . . . . . . . . . . . . . 28 127 5.2.3. Cache Control Extensions . . . . . . . . . . . . . . 29 128 5.2.4. Cache Directive Registry . . . . . . . . . . . . . . 30 129 5.3. Expires . . . . . . . . . . . . . . . . . . . . . . . . . 30 130 5.4. Pragma . . . . . . . . . . . . . . . . . . . . . . . . . 31 131 5.5. Warning . . . . . . . . . . . . . . . . . . . . . . . . . 31 132 6. Relationship to Applications . . . . . . . . . . . . . . . . 31 133 7. Security Considerations . . . . . . . . . . . . . . . . . . . 32 134 7.1. Cache Poisoning . . . . . . . . . . . . . . . . . . . . . 32 135 7.2. Timing Attacks . . . . . . . . . . . . . . . . . . . . . 32 136 7.3. Caching of Sensitive Information . . . . . . . . . . . . 33 137 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 33 138 8.1. Header Field Registration . . . . . . . . . . . . . . . . 33 139 8.2. Cache Directive Registration . . . . . . . . . . . . . . 33 140 8.3. Warn Code Registry . . . . . . . . . . . . . . . . . . . 33 141 9. References . . . . . . . . . . . . . . . . . . . . . . . . . 33 142 9.1. Normative References . . . . . . . . . . . . . . . . . . 33 143 9.2. Informative References . . . . . . . . . . . . . . . . . 34 144 Appendix A. Collected ABNF . . . . . . . . . . . . . . . . . . . 36 145 Appendix B. Changes from RFC 7234 . . . . . . . . . . . . . . . 36 146 Appendix C. Change Log . . . . . . . . . . . . . . . . . . . . . 36 147 C.1. Between RFC7234 and draft 00 . . . . . . . . . . . . . . 36 148 C.2. Since draft-ietf-httpbis-cache-00 . . . . . . . . . . . . 37 149 C.3. Since draft-ietf-httpbis-cache-01 . . . . . . . . . . . . 37 150 C.4. Since draft-ietf-httpbis-cache-02 . . . . . . . . . . . . 37 151 C.5. Since draft-ietf-httpbis-cache-03 . . . . . . . . . . . . 38 152 C.6. Since draft-ietf-httpbis-cache-04 . . . . . . . . . . . . 38 153 C.7. Since draft-ietf-httpbis-cache-05 . . . . . . . . . . . . 38 154 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 155 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 40 156 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 40 158 1. Introduction 160 The Hypertext Transfer Protocol (HTTP) is a stateless application- 161 level request/response protocol that uses extensible semantics and 162 self-descriptive messages for flexible interaction with network-based 163 hypertext information systems. HTTP is defined by a series of 164 documents that collectively form the HTTP/1.1 specification: 166 o "HTTP Semantics" [Semantics] 168 o "HTTP Caching" (this document) 170 o "HTTP/1.1 Messaging" [Messaging] 172 HTTP is typically used for distributed information systems, where 173 performance can be improved by the use of response caches. This 174 document defines aspects of HTTP related to caching and reusing 175 response messages. 177 An HTTP cache is a local store of response messages and the subsystem 178 that controls storage, retrieval, and deletion of messages in it. A 179 cache stores cacheable responses in order to reduce the response time 180 and network bandwidth consumption on future, equivalent requests. 181 Any client or server MAY employ a cache, though a cache cannot be 182 used by a server that is acting as a tunnel. 184 A shared cache is a cache that stores responses to be reused by more 185 than one user; shared caches are usually (but not always) deployed as 186 a part of an intermediary. A private cache, in contrast, is 187 dedicated to a single user; often, they are deployed as a component 188 of a user agent. 190 The goal of caching in HTTP is to significantly improve performance 191 by reusing a prior response message to satisfy a current request. A 192 stored response is considered "fresh", as defined in Section 4.2, if 193 the response can be reused without "validation" (checking with the 194 origin server to see if the cached response remains valid for this 195 request). A fresh response can therefore reduce both latency and 196 network overhead each time it is reused. When a cached response is 197 not fresh, it might still be reusable if it can be freshened by 198 validation (Section 4.3) or if the origin is unavailable 199 (Section 4.2.4). 201 This document obsoletes RFC 7234, with the changes being summarized 202 in Appendix B. 204 1.1. Requirements Notation 206 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 207 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 208 document are to be interpreted as described in [RFC2119]. 210 Conformance criteria and considerations regarding error handling are 211 defined in Section 3 of [Semantics]. 213 1.2. Syntax Notation 215 This specification uses the Augmented Backus-Naur Form (ABNF) 216 notation of [RFC5234], extended with the notation for case- 217 sensitivity in strings defined in [RFC7405]. 219 It also uses a list extension, defined in Section 12 of [Semantics], 220 that allows for compact definition of comma-separated lists using a 221 '#' operator (similar to how the '*' operator indicates repetition). 222 Appendix A shows the collected grammar with all list operators 223 expanded to standard ABNF notation. 225 The following core rules are included by reference, as defined in 226 [RFC5234], Appendix B.1: ALPHA (letters), CR (carriage return), CRLF 227 (CR LF), CTL (controls), DIGIT (decimal 0-9), DQUOTE (double quote), 228 HEXDIG (hexadecimal 0-9/A-F/a-f), HTAB (horizontal tab), LF (line 229 feed), OCTET (any 8-bit sequence of data), SP (space), and VCHAR (any 230 visible [USASCII] character). 232 The rules below are defined in [Semantics]: 234 HTTP-date = 235 OWS = 236 field-name = 237 quoted-string = 238 token = 240 1.3. Delta Seconds 242 The delta-seconds rule specifies a non-negative integer, representing 243 time in seconds. 245 delta-seconds = 1*DIGIT 247 A recipient parsing a delta-seconds value and converting it to binary 248 form ought to use an arithmetic type of at least 31 bits of non- 249 negative integer range. If a cache receives a delta-seconds value 250 greater than the greatest integer it can represent, or if any of its 251 subsequent calculations overflows, the cache MUST consider the value 252 to be either 2147483648 (2^31) or the greatest positive integer it 253 can conveniently represent. 255 Note: The value 2147483648 is here for historical reasons, 256 effectively represents infinity (over 68 years), and does not need 257 to be stored in binary form; an implementation could produce it as 258 a canned string if any overflow occurs, even if the calculations 259 are performed with an arithmetic type incapable of directly 260 representing that number. What matters here is that an overflow 261 be detected and not treated as a negative value in later 262 calculations. 264 2. Overview of Cache Operation 266 Proper cache operation preserves the semantics of HTTP transfers 267 ([Semantics]) while reducing the transfer of information already held 268 in the cache. Although caching is an entirely OPTIONAL feature of 269 HTTP, it can be assumed that reusing a cached response is desirable 270 and that such reuse is the default behavior when no requirement or 271 local configuration prevents it. Therefore, HTTP cache requirements 272 are focused on preventing a cache from either storing a non-reusable 273 response or reusing a stored response inappropriately, rather than 274 mandating that caches always store and reuse particular responses. 276 The base cache key consists of the request method and target URI used 277 to retrieve the stored response; the method determines under which 278 circumstances that response can be used to satisfy a request. 279 However, many HTTP caches in common use today only cache GET 280 responses, and therefore only use the URI as the cache key, 281 forwarding other methods. 283 If a request target is subject to content negotiation, the cache 284 might store multiple responses for it. Caches differentiate these 285 responses by incorporating values of the original request's selecting 286 header fields into the cache key as well, as per Section 4.1. 288 Furthermore, caches might incorporate additional material into the 289 cache key. For example, user agent caches might include the 290 referring site's identity, thereby "double keying" the cache to avoid 291 some privacy risks (see Section 7.2). 293 Most commonly, caches store the successful result of a retrieval 294 request: i.e., a 200 (OK) response to a GET request, which contains a 295 representation of the resource identified by the request target 296 (Section 7.3.1 of [Semantics]). However, it is also possible to 297 store redirects, negative results (e.g., 404 (Not Found)), incomplete 298 results (e.g., 206 (Partial Content)), and responses to methods other 299 than GET if the method's definition allows such caching and defines 300 something suitable for use as a cache key. 302 A cache is disconnected when it cannot contact the origin server or 303 otherwise find a forward path for a given request. A disconnected 304 cache can serve stale responses in some circumstances 305 (Section 4.2.4). 307 3. Storing Responses in Caches 309 A cache MUST NOT store a response to any request, unless: 311 o The request method is understood by the cache, and 313 o the response status code is final (see Section 9.3 of 314 [Messaging]), and 316 o the response status code is understood by the cache, and 318 o the "no-store" cache directive (see Section 5.2) does not appear 319 in the response, and 321 o the "private" response directive (see Section 5.2.2.6) does not 322 appear in the response, if the cache is shared, and 324 o the Authorization header field (see Section 8.5.3 of [Semantics]) 325 does not appear in the request, if the cache is shared, unless the 326 response explicitly allows it (see Section 3.2), and 328 o the response either: 330 * contains an Expires header field (see Section 5.3), or 332 * contains a max-age response directive (see Section 5.2.2.8), or 333 * contains a s-maxage response directive (see Section 5.2.2.9) 334 and the cache is shared, or 336 * contains a Cache Control Extension (see Section 5.2.3) that 337 allows it to be cached, or 339 * has a status code that is defined as heuristically cacheable 340 (see Section 4.2.2), or 342 * contains a public response directive (see Section 5.2.2.5). 344 Note that any of the requirements listed above can be overridden by a 345 cache-control extension; see Section 5.2.3. 347 In this context, a cache has "understood" a request method or a 348 response status code if it recognizes it and implements all specified 349 caching-related behavior. 351 Note that, in normal operation, some caches will not store a response 352 that has neither a cache validator nor an explicit expiration time, 353 as such responses are not usually useful to store. However, caches 354 are not prohibited from storing such responses. 356 3.1. Storing Incomplete Responses 358 A response message is considered complete when all of the octets 359 indicated by its framing are available. Note that, when no explicit 360 framing is provided, a response message that is ended by the 361 connection's close is considered complete even though it might be 362 indistinguishable from an incomplete response (see [Messaging], 363 Section 6.3). A cache SHOULD consider a close-terminated response 364 incomplete if the connection termination is detected to be an error. 365 A server that wishes to avoid premature termination resulting in an 366 incorrect cached response SHOULD send the response with explicit 367 framing. 369 If the request method is GET, the response status code is 200 (OK), 370 and the entire response header section has been received, a cache MAY 371 store an incomplete response message body if the stored response is 372 recorded as incomplete. Likewise, a 206 (Partial Content) response 373 MAY be stored as if it were an incomplete 200 (OK) response. 374 However, a cache MUST NOT store incomplete or partial-content 375 responses if it does not support the Range and Content-Range header 376 fields or if it does not understand the range units used in those 377 fields. 379 A cache MAY complete a stored incomplete response by making a 380 subsequent range request (Section 8.3 of [Semantics]) and combining 381 the successful response with the stored response, as defined in 382 Section 3.3. A cache MUST NOT use an incomplete response to answer 383 requests unless the response has been made complete or the request is 384 partial and specifies a range that is wholly within the incomplete 385 response. A cache MUST NOT send a partial response to a client 386 without explicitly marking it as such using the 206 (Partial Content) 387 status code. 389 3.2. Storing Responses to Authenticated Requests 391 A shared cache MUST NOT use a cached response to a request with an 392 Authorization header field (Section 8.5.3 of [Semantics]) to satisfy 393 any subsequent request unless a response directive that allows such 394 responses to be stored is present. 396 In this specification, the following Cache-Control response 397 directives (Section 5.2.2) have such an effect: must-revalidate, 398 public, and s-maxage. 400 3.3. Combining Partial Content 402 A response might transfer only a partial representation if the 403 connection closed prematurely or if the request used one or more 404 Range specifiers (Section 8.3 of [Semantics]). After several such 405 transfers, a cache might have received several ranges of the same 406 representation. A cache MAY combine these ranges into a single 407 stored response, and reuse that response to satisfy later requests, 408 if they all share the same strong validator and the cache complies 409 with the client requirements in Section 9.3.7.3 of [Semantics]. 411 When combining the new response with one or more stored responses, a 412 cache MUST use the header fields provided in the new response, aside 413 from Content-Range, to replace all instances of the corresponding 414 header fields in the stored response. 416 4. Constructing Responses from Caches 418 When presented with a request, a cache MUST NOT reuse a stored 419 response, unless: 421 o The presented effective request URI (Section 5.3 of [Semantics]) 422 and that of the stored response match, and 424 o the request method associated with the stored response allows it 425 to be used for the presented request, and 427 o selecting header fields nominated by the stored response (if any) 428 match those presented (see Section 4.1), and 430 o the stored response does not contain the no-cache cache directive 431 (Section 5.2.2.2), unless it is successfully validated 432 (Section 4.3), and 434 o the stored response is either: 436 * fresh (see Section 4.2), or 438 * allowed to be served stale (see Section 4.2.4), or 440 * successfully validated (see Section 4.3). 442 Note that any of the requirements listed above can be overridden by a 443 cache-control extension; see Section 5.2.3. 445 When a stored response is used to satisfy a request without 446 validation, a cache MUST generate an Age header field (Section 5.1), 447 replacing any present in the response with a value equal to the 448 stored response's current_age; see Section 4.2.3. 450 A cache MUST write through requests with methods that are unsafe 451 (Section 7.2.1 of [Semantics]) to the origin server; i.e., a cache is 452 not allowed to generate a reply to such a request before having 453 forwarded the request and having received a corresponding response. 455 Also, note that unsafe requests might invalidate already-stored 456 responses; see Section 4.4. 458 When more than one suitable response is stored, a cache MUST use the 459 most recent one (as determined by the Date header field). It can 460 also forward the request with "Cache-Control: max-age=0" or "Cache- 461 Control: no-cache" to disambiguate which response to use. 463 A cache that does not have a clock available MUST NOT use stored 464 responses without revalidating them upon every use. 466 4.1. Calculating Cache Keys with Vary 468 When a cache receives a request that can be satisfied by a stored 469 response that has a Vary header field (Section 10.1.4 of 470 [Semantics]), it MUST NOT use that response unless all of the 471 selecting header fields nominated by the Vary header field match in 472 both the original request (i.e., that associated with the stored 473 response), and the presented request. 475 The selecting header fields from two requests are defined to match if 476 and only if those in the first request can be transformed to those in 477 the second request by applying any of the following: 479 o adding or removing whitespace, where allowed in the header field's 480 syntax 482 o combining multiple header fields with the same field name (see 483 Section 4.2 of [Semantics]) 485 o normalizing both header field values in a way that is known to 486 have identical semantics, according to the header field's 487 specification (e.g., reordering field values when order is not 488 significant; case-normalization, where values are defined to be 489 case-insensitive) 491 If (after any normalization that might take place) a header field is 492 absent from a request, it can only match another request if it is 493 also absent there. 495 A Vary header field-value of "*" always fails to match. 497 The stored response with matching selecting header fields is known as 498 the selected response. 500 If multiple selected responses are available (potentially including 501 responses without a Vary header field), the cache will need to choose 502 one to use. When a selecting header field has a known mechanism for 503 doing so (e.g., qvalues on Accept and similar request header fields), 504 that mechanism MAY be used to select preferred responses; of the 505 remainder, the most recent response (as determined by the Date header 506 field) is used, as per Section 4. 508 Note that in practice, some resources might send the Vary header 509 field on responses inconsistently. When a cache has multiple 510 responses for a given target URI, and one or more omits the Vary 511 header field, it SHOULD use the most recent non-empty value available 512 to select an appropriate response for the request. 514 If no selected response is available, the cache cannot satisfy the 515 presented request. Typically, it is forwarded to the origin server 516 in a (possibly conditional; see Section 4.3) request. 518 4.2. Freshness 520 A fresh response is one whose age has not yet exceeded its freshness 521 lifetime. Conversely, a stale response is one where it has. 523 A response's freshness lifetime is the length of time between its 524 generation by the origin server and its expiration time. An explicit 525 expiration time is the time at which the origin server intends that a 526 stored response can no longer be used by a cache without further 527 validation, whereas a heuristic expiration time is assigned by a 528 cache when no explicit expiration time is available. 530 A response's age is the time that has passed since it was generated 531 by, or successfully validated with, the origin server. 533 When a response is "fresh" in the cache, it can be used to satisfy 534 subsequent requests without contacting the origin server, thereby 535 improving efficiency. 537 The primary mechanism for determining freshness is for an origin 538 server to provide an explicit expiration time in the future, using 539 either the Expires header field (Section 5.3) or the max-age response 540 directive (Section 5.2.2.8). Generally, origin servers will assign 541 future explicit expiration times to responses in the belief that the 542 representation is not likely to change in a semantically significant 543 way before the expiration time is reached. 545 If an origin server wishes to force a cache to validate every 546 request, it can assign an explicit expiration time in the past to 547 indicate that the response is already stale. Compliant caches will 548 normally validate a stale cached response before reusing it for 549 subsequent requests (see Section 4.2.4). 551 Since origin servers do not always provide explicit expiration times, 552 caches are also allowed to use a heuristic to determine an expiration 553 time under certain circumstances (see Section 4.2.2). 555 The calculation to determine if a response is fresh is: 557 response_is_fresh = (freshness_lifetime > current_age) 559 freshness_lifetime is defined in Section 4.2.1; current_age is 560 defined in Section 4.2.3. 562 Clients can send the max-age or min-fresh request directives 563 (Section 5.2.1) to constrain or relax freshness calculations for the 564 corresponding response. However, caches are not required to honor 565 them. 567 When calculating freshness, to avoid common problems in date parsing: 569 o Although all date formats are specified to be case-sensitive, a 570 cache recipient SHOULD match day, week, and time-zone names case- 571 insensitively. 573 o If a cache recipient's internal implementation of time has less 574 resolution than the value of an HTTP-date, the recipient MUST 575 internally represent a parsed Expires date as the nearest time 576 equal to or earlier than the received value. 578 o A cache recipient MUST NOT allow local time zones to influence the 579 calculation or comparison of an age or expiration time. 581 o A cache recipient SHOULD consider a date with a zone abbreviation 582 other than GMT or UTC to be invalid for calculating expiration. 584 Note that freshness applies only to cache operation; it cannot be 585 used to force a user agent to refresh its display or reload a 586 resource. See Section 6 for an explanation of the difference between 587 caches and history mechanisms. 589 4.2.1. Calculating Freshness Lifetime 591 A cache can calculate the freshness lifetime (denoted as 592 freshness_lifetime) of a response by using the first match of the 593 following: 595 o If the cache is shared and the s-maxage response directive 596 (Section 5.2.2.9) is present, use its value, or 598 o If the max-age response directive (Section 5.2.2.8) is present, 599 use its value, or 601 o If the Expires response header field (Section 5.3) is present, use 602 its value minus the value of the Date response header field, or 604 o Otherwise, no explicit expiration time is present in the response. 605 A heuristic freshness lifetime might be applicable; see 606 Section 4.2.2. 608 Note that this calculation is not vulnerable to clock skew, since all 609 of the information comes from the origin server. 611 When there is more than one value present for a given directive 612 (e.g., two Expires header fields, multiple Cache-Control: max-age 613 directives), the directive's value is considered invalid. Caches are 614 encouraged to consider responses that have invalid freshness 615 information to be stale. 617 4.2.2. Calculating Heuristic Freshness 619 Since origin servers do not always provide explicit expiration times, 620 a cache MAY assign a heuristic expiration time when an explicit time 621 is not specified, employing algorithms that use other header field 622 values (such as the Last-Modified time) to estimate a plausible 623 expiration time. This specification does not provide specific 624 algorithms, but does impose worst-case constraints on their results. 626 A cache MUST NOT use heuristics to determine freshness when an 627 explicit expiration time is present in the stored response. Because 628 of the requirements in Section 3, this means that, effectively, 629 heuristics can only be used on responses without explicit freshness 630 whose status codes are defined as "heuristically cacheable" (e.g., 631 see Section 9.1 of [Semantics]), and those responses without explicit 632 freshness that have been marked as explicitly cacheable (e.g., with a 633 "public" response directive). 635 Note that in previous specifications heuristically cacheable response 636 status codes were called "cacheable by default." 638 If the response has a Last-Modified header field (Section 10.2.2 of 639 [Semantics]), caches are encouraged to use a heuristic expiration 640 value that is no more than some fraction of the interval since that 641 time. A typical setting of this fraction might be 10%. 643 Note: Section 13.9 of [RFC2616] prohibited caches from calculating 644 heuristic freshness for URIs with query components (i.e., those 645 containing '?'). In practice, this has not been widely 646 implemented. Therefore, origin servers are encouraged to send 647 explicit directives (e.g., Cache-Control: no-cache) if they wish 648 to preclude caching. 650 4.2.3. Calculating Age 652 The Age header field is used to convey an estimated age of the 653 response message when obtained from a cache. The Age field value is 654 the cache's estimate of the number of seconds since the response was 655 generated or validated by the origin server. In essence, the Age 656 value is the sum of the time that the response has been resident in 657 each of the caches along the path from the origin server, plus the 658 amount of time it has been in transit along network paths. 660 The following data is used for the age calculation: 662 age_value The term "age_value" denotes the value of the Age header 663 field (Section 5.1), in a form appropriate for arithmetic 664 operation; or 0, if not available. 666 date_value The term "date_value" denotes the value of the Date 667 header field, in a form appropriate for arithmetic operations. 668 See Section 10.1.1.2 of [Semantics] for the definition of the Date 669 header field, and for requirements regarding responses without it. 671 now The term "now" means "the current value of the clock at the host 672 performing the calculation". A host ought to use NTP ([RFC5905]) 673 or some similar protocol to synchronize its clocks to Coordinated 674 Universal Time. 676 request_time The current value of the clock at the host at the time 677 the request resulting in the stored response was made. 679 response_time The current value of the clock at the host at the time 680 the response was received. 682 A response's age can be calculated in two entirely independent ways: 684 1. the "apparent_age": response_time minus date_value, if the local 685 clock is reasonably well synchronized to the origin server's 686 clock. If the result is negative, the result is replaced by 687 zero. 689 2. the "corrected_age_value", if all of the caches along the 690 response path implement HTTP/1.1 or greater. A cache MUST 691 interpret this value relative to the time the request was 692 initiated, not the time that the response was received. 694 apparent_age = max(0, response_time - date_value); 696 response_delay = response_time - request_time; 697 corrected_age_value = age_value + response_delay; 699 These are combined as 701 corrected_initial_age = max(apparent_age, corrected_age_value); 703 unless the cache is confident in the value of the Age header field 704 (e.g., because there are no HTTP/1.0 hops in the Via header field), 705 in which case the corrected_age_value MAY be used as the 706 corrected_initial_age. 708 The current_age of a stored response can then be calculated by adding 709 the amount of time (in seconds) since the stored response was last 710 validated by the origin server to the corrected_initial_age. 712 resident_time = now - response_time; 713 current_age = corrected_initial_age + resident_time; 715 4.2.4. Serving Stale Responses 717 A "stale" response is one that either has explicit expiry information 718 or is allowed to have heuristic expiry calculated, but is not fresh 719 according to the calculations in Section 4.2. 721 A cache MUST NOT generate a stale response if it is prohibited by an 722 explicit in-protocol directive (e.g., by a "no-store" or "no-cache" 723 cache directive, a "must-revalidate" cache-response-directive, or an 724 applicable "s-maxage" or "proxy-revalidate" cache-response-directive; 725 see Section 5.2.2). 727 A cache MUST NOT generate a stale response unless it is disconnected 728 or doing so is explicitly permitted by the client or origin server 729 (e.g., by the max-stale request directive in Section 5.2.1, by 730 extension directives such as those defined in [RFC5861], or by 731 configuration in accordance with an out-of-band contract). 733 4.3. Validation 735 When a cache has one or more stored responses for a requested URI, 736 but cannot serve any of them (e.g., because they are not fresh, or 737 one cannot be selected; see Section 4.1), it can use the conditional 738 request mechanism Section 8.2 of [Semantics] in the forwarded request 739 to give the next inbound server an opportunity to select a valid 740 stored response to use, updating the stored metadata in the process, 741 or to replace the stored response(s) with a new response. This 742 process is known as "validating" or "revalidating" the stored 743 response. 745 4.3.1. Sending a Validation Request 747 When generating a conditional request for validation, a cache starts 748 with either a request it is attempting to satisfy, or -- if it is 749 initiating the request independently -- it synthesises a request 750 using a stored response by copying the method, request-target, and 751 request header fields identified by the Vary header field 752 Section 4.1. 754 It then updates that request with one or more precondition header 755 fields. These contain validator metadata sourced from stored 756 response(s) that have the same cache key. 758 The precondition header fields are then compared by recipients to 759 determine whether any stored response is equivalent to a current 760 representation of the resource. 762 One such validator is the timestamp given in a Last-Modified header 763 field (Section 10.2.2 of [Semantics]), which can be used in an If- 764 Modified-Since header field for response validation, or in an If- 765 Unmodified-Since or If-Range header field for representation 766 selection (i.e., the client is referring specifically to a previously 767 obtained representation with that timestamp). 769 Another validator is the entity-tag given in an ETag header field 770 (Section 10.2.3 of [Semantics]). One or more entity-tags, indicating 771 one or more stored responses, can be used in an If-None-Match header 772 field for response validation, or in an If-Match or If-Range header 773 field for representation selection (i.e., the client is referring 774 specifically to one or more previously obtained representations with 775 the listed entity-tags). 777 4.3.2. Handling a Received Validation Request 779 Each client in the request chain may have its own cache, so it is 780 common for a cache at an intermediary to receive conditional requests 781 from other (outbound) caches. Likewise, some user agents make use of 782 conditional requests to limit data transfers to recently modified 783 representations or to complete the transfer of a partially retrieved 784 representation. 786 If a cache receives a request that can be satisfied by reusing one of 787 its stored 200 (OK) or 206 (Partial Content) responses, the cache 788 SHOULD evaluate any applicable conditional header field preconditions 789 received in that request with respect to the corresponding validators 790 contained within the selected response. A cache MUST NOT evaluate 791 conditional header fields that are only applicable to an origin 792 server, found in a request with semantics that cannot be satisfied 793 with a cached response, or applied to a target resource for which it 794 has no stored responses; such preconditions are likely intended for 795 some other (inbound) server. 797 The proper evaluation of conditional requests by a cache depends on 798 the received precondition header fields and their precedence, as 799 defined in Section 8.2.2 of [Semantics]. The If-Match and If- 800 Unmodified-Since conditional header fields are not applicable to a 801 cache. 803 A request containing an If-None-Match header field (Section 8.2.4 of 804 [Semantics]) indicates that the client wants to validate one or more 805 of its own stored responses in comparison to whichever stored 806 response is selected by the cache. If the field-value is "*", or if 807 the field-value is a list of entity-tags and at least one of them 808 matches the entity-tag of the selected stored response, a cache 809 recipient SHOULD generate a 304 (Not Modified) response (using the 810 metadata of the selected stored response) instead of sending that 811 stored response. 813 When a cache decides to revalidate its own stored responses for a 814 request that contains an If-None-Match list of entity-tags, the cache 815 MAY combine the received list with a list of entity-tags from its own 816 stored set of responses (fresh or stale) and send the union of the 817 two lists as a replacement If-None-Match header field value in the 818 forwarded request. If a stored response contains only partial 819 content, the cache MUST NOT include its entity-tag in the union 820 unless the request is for a range that would be fully satisfied by 821 that partial stored response. If the response to the forwarded 822 request is 304 (Not Modified) and has an ETag header field value with 823 an entity-tag that is not in the client's list, the cache MUST 824 generate a 200 (OK) response for the client by reusing its 825 corresponding stored response, as updated by the 304 response 826 metadata (Section 4.3.4). 828 If an If-None-Match header field is not present, a request containing 829 an If-Modified-Since header field (Section 8.2.5 of [Semantics]) 830 indicates that the client wants to validate one or more of its own 831 stored responses by modification date. A cache recipient SHOULD 832 generate a 304 (Not Modified) response (using the metadata of the 833 selected stored response) if one of the following cases is true: 1) 834 the selected stored response has a Last-Modified field-value that is 835 earlier than or equal to the conditional timestamp; 2) no Last- 836 Modified field is present in the selected stored response, but it has 837 a Date field-value that is earlier than or equal to the conditional 838 timestamp; or, 3) neither Last-Modified nor Date is present in the 839 selected stored response, but the cache recorded it as having been 840 received at a time earlier than or equal to the conditional 841 timestamp. 843 A cache that implements partial responses to range requests, as 844 defined in Section 8.3 of [Semantics], also needs to evaluate a 845 received If-Range header field (Section 8.2.7 of [Semantics]) with 846 respect to its selected stored response. 848 4.3.3. Handling a Validation Response 850 Cache handling of a response to a conditional request is dependent 851 upon its status code: 853 o A 304 (Not Modified) response status code indicates that the 854 stored response can be updated and reused; see Section 4.3.4. 856 o A full response (i.e., one with a payload body) indicates that 857 none of the stored responses nominated in the conditional request 858 is suitable. Instead, the cache MUST use the full response to 859 satisfy the request and MAY replace the stored response(s). 861 o However, if a cache receives a 5xx (Server Error) response while 862 attempting to validate a response, it can either forward this 863 response to the requesting client, or act as if the server failed 864 to respond. In the latter case, the cache MAY send a previously 865 stored response (see Section 4.2.4). 867 4.3.4. Freshening Stored Responses upon Validation 869 When a cache receives a 304 (Not Modified) response and already has 870 one or more stored 200 (OK) responses for the applicable cache key, 871 the cache needs to identify which (if any) are to be updated by the 872 new information provided, and then do so. 874 The stored response(s) to update are identified by using the first 875 match (if any) of the following: 877 o If the new response contains a strong validator (see 878 Section 10.2.1 of [Semantics]), then that strong validator 879 identifies the selected representation for update. All of the 880 stored responses with the same strong validator are identified for 881 update. If none of the stored responses contain the same strong 882 validator, then the cache MUST NOT use the new response to update 883 any stored responses. 885 o If the new response contains a weak validator and that validator 886 corresponds to one of the cache's stored responses, then the most 887 recent of those matching stored responses is identified for 888 update. 890 o If the new response does not include any form of validator (such 891 as in the case where a client generates an If-Modified-Since 892 request from a source other than the Last-Modified response header 893 field), and there is only one stored response, and that stored 894 response also lacks a validator, then that stored response is 895 identified for update. 897 For each stored response identified for update, the cache MUST use 898 the header fields provided in the 304 (Not Modified) response to 899 replace all instances of the corresponding header fields in the 900 stored response. 902 4.3.5. Freshening Responses with HEAD 904 A response to the HEAD method is identical to what an equivalent 905 request made with a GET would have been, except it lacks a body. 906 This property of HEAD responses can be used to invalidate or update a 907 cached GET response if the more efficient conditional GET request 908 mechanism is not available (due to no validators being present in the 909 stored response) or if transmission of the representation body is not 910 desired even if it has changed. 912 When a cache makes an inbound HEAD request for a given request target 913 and receives a 200 (OK) response, the cache SHOULD update or 914 invalidate each of its stored GET responses that could have been 915 selected for that request (see Section 4.1). 917 For each of the stored responses that could have been selected, if 918 the stored response and HEAD response have matching values for any 919 received validator fields (ETag and Last-Modified) and, if the HEAD 920 response has a Content-Length header field, the value of Content- 921 Length matches that of the stored response, the cache SHOULD update 922 the stored response as described below; otherwise, the cache SHOULD 923 consider the stored response to be stale. 925 If a cache updates a stored response with the metadata provided in a 926 HEAD response, the cache MUST use the header fields provided in the 927 HEAD response to replace all instances of the corresponding header 928 fields in the stored response and append new header fields to the 929 stored response's header section unless otherwise restricted by the 930 Cache-Control header field. 932 4.4. Invalidation 934 Because unsafe request methods (Section 7.2.1 of [Semantics]) such as 935 PUT, POST or DELETE have the potential for changing state on the 936 origin server, intervening caches can use them to keep their contents 937 up to date. 939 A cache MUST invalidate the effective Request URI (Section 5.3 of 940 [Semantics]) as well as the URI(s) in the Location and Content- 941 Location response header fields (if present) when a non-error status 942 code is received in response to an unsafe request method. 944 However, a cache MUST NOT invalidate a URI from a Location or 945 Content-Location response header field if the host part of that URI 946 differs from the host part in the effective request URI (Section 5.3 947 of [Semantics]). This helps prevent denial-of-service attacks. 949 A cache MUST invalidate the effective request URI (Section 5.3 of 950 [Semantics]) when it receives a non-error response to a request with 951 a method whose safety is unknown. 953 Here, a "non-error response" is one with a 2xx (Successful) or 3xx 954 (Redirection) status code. "Invalidate" means that the cache will 955 either remove all stored responses related to the effective request 956 URI or will mark these as "invalid" and in need of a mandatory 957 validation before they can be sent in response to a subsequent 958 request. 960 Note that this does not guarantee that all appropriate responses are 961 invalidated. For example, a state-changing request might invalidate 962 responses in the caches it travels through, but relevant responses 963 still might be stored in other caches that it has not. 965 5. Header Field Definitions 967 This section defines the syntax and semantics of HTTP header fields 968 related to caching. 970 +-------------------+-----------+--------------+ 971 | Header Field Name | Status | Reference | 972 +-------------------+-----------+--------------+ 973 | Age | standard | Section 5.1 | 974 | Cache-Control | standard | Section 5.2 | 975 | Expires | standard | Section 5.3 | 976 | Pragma | standard | Section 5.4 | 977 | Warning | obsoleted | Section 5.5 | 978 +-------------------+-----------+--------------+ 980 Table 1 982 5.1. Age 984 The "Age" header field conveys the sender's estimate of the amount of 985 time since the response was generated or successfully validated at 986 the origin server. Age values are calculated as specified in 987 Section 4.2.3. 989 Age = delta-seconds 991 The Age field-value is a non-negative integer, representing time in 992 seconds (see Section 1.3). 994 The presence of an Age header field implies that the response was not 995 generated or validated by the origin server for this request. 996 However, lack of an Age header field does not imply the origin was 997 contacted, since the response might have been received from an 998 HTTP/1.0 cache that does not implement Age. 1000 5.2. Cache-Control 1002 The "Cache-Control" header field is used to specify directives for 1003 caches along the request/response chain. Such cache directives are 1004 unidirectional in that the presence of a directive in a request does 1005 not imply that the same directive is present in the response, or to 1006 be repeated in it. 1008 See Section 5.2.3 for information about how Cache-Control directives 1009 defined elsewhere are handled. 1011 Note: Some HTTP/1.0 caches might not implement Cache-Control. 1013 A proxy, whether or not it implements a cache, MUST pass cache 1014 directives through in forwarded messages, regardless of their 1015 significance to that application, since the directives might be 1016 applicable to all recipients along the request/response chain. It is 1017 not possible to target a directive to a specific cache. 1019 Cache directives are identified by a token, to be compared case- 1020 insensitively, and have an optional argument, that can use both token 1021 and quoted-string syntax. For the directives defined below that 1022 define arguments, recipients ought to accept both forms, even if one 1023 is documented to be preferred. For any directive not defined by this 1024 specification, a recipient MUST accept both forms. 1026 Cache-Control = 1#cache-directive 1028 cache-directive = token [ "=" ( token / quoted-string ) ] 1030 For the cache directives defined below, no argument is defined (nor 1031 allowed) unless stated otherwise. 1033 +------------------+-----------------------------------+ 1034 | Cache Directive | Reference | 1035 +------------------+-----------------------------------+ 1036 | max-age | Section 5.2.1.1, Section 5.2.2.8 | 1037 | max-stale | Section 5.2.1.2 | 1038 | min-fresh | Section 5.2.1.3 | 1039 | must-revalidate | Section 5.2.2.1 | 1040 | no-cache | Section 5.2.1.4, Section 5.2.2.2 | 1041 | no-store | Section 5.2.1.5, Section 5.2.2.3 | 1042 | no-transform | Section 5.2.1.6, Section 5.2.2.4 | 1043 | only-if-cached | Section 5.2.1.7 | 1044 | private | Section 5.2.2.6 | 1045 | proxy-revalidate | Section 5.2.2.7 | 1046 | public | Section 5.2.2.5 | 1047 | s-maxage | Section 5.2.2.9 | 1048 +------------------+-----------------------------------+ 1050 Table 2 1052 5.2.1. Request Cache-Control Directives 1054 This section defines cache request directives. They are advisory; 1055 caches MAY implement them, but are not required to. 1057 5.2.1.1. max-age 1059 Argument syntax: 1061 delta-seconds (see Section 1.3) 1063 The "max-age" request directive indicates that the client prefers a 1064 response whose age is less than or equal to the specified number of 1065 seconds. Unless the max-stale request directive is also present, the 1066 client does not wish to receive a stale response. 1068 This directive uses the token form of the argument syntax: e.g., 1069 'max-age=5' not 'max-age="5"'. A sender SHOULD NOT generate the 1070 quoted-string form. 1072 5.2.1.2. max-stale 1074 Argument syntax: 1076 delta-seconds (see Section 1.3) 1078 The "max-stale" request directive indicates that the client is 1079 willing to accept a response that has exceeded its freshness 1080 lifetime. If a value is present, then the client is willing to 1081 accept a response that has exceeded its freshness lifetime by no more 1082 than the specified number of seconds. If no value is assigned to 1083 max-stale, then the client is willing to accept a stale response of 1084 any age. 1086 This directive uses the token form of the argument syntax: e.g., 1087 'max-stale=10' not 'max-stale="10"'. A sender SHOULD NOT generate 1088 the quoted-string form. 1090 5.2.1.3. min-fresh 1092 Argument syntax: 1094 delta-seconds (see Section 1.3) 1096 The "min-fresh" request directive indicates that the client prefers a 1097 response whose freshness lifetime is no less than its current age 1098 plus the specified time in seconds. That is, the client wants a 1099 response that will still be fresh for at least the specified number 1100 of seconds. 1102 This directive uses the token form of the argument syntax: e.g., 1103 'min-fresh=20' not 'min-fresh="20"'. A sender SHOULD NOT generate 1104 the quoted-string form. 1106 5.2.1.4. no-cache 1108 The "no-cache" request directive indicates that the client prefers 1109 stored response not be used to satisfy the request without successful 1110 validation on the origin server. 1112 5.2.1.5. no-store 1114 The "no-store" request directive indicates that a cache MUST NOT 1115 store any part of either this request or any response to it. This 1116 directive applies to both private and shared caches. "MUST NOT 1117 store" in this context means that the cache MUST NOT intentionally 1118 store the information in non-volatile storage, and MUST make a best- 1119 effort attempt to remove the information from volatile storage as 1120 promptly as possible after forwarding it. 1122 This directive is NOT a reliable or sufficient mechanism for ensuring 1123 privacy. In particular, malicious or compromised caches might not 1124 recognize or obey this directive, and communications networks might 1125 be vulnerable to eavesdropping. 1127 Note that if a request containing this directive is satisfied from a 1128 cache, the no-store request directive does not apply to the already 1129 stored response. 1131 5.2.1.6. no-transform 1133 The "no-transform" request directive indicates that the client is 1134 asking for intermediares (whether or not they implement a cache) to 1135 avoid transforming the payload, as defined in Section 5.5.2 of 1136 [Semantics]. 1138 5.2.1.7. only-if-cached 1140 The "only-if-cached" request directive indicates that the client only 1141 wishes to obtain a stored response. Caches that honor this request 1142 directive SHOULD, upon receiving it, either respond using a stored 1143 response that is consistent with the other constraints of the 1144 request, or respond with a 504 (Gateway Timeout) status code. 1146 5.2.2. Response Cache-Control Directives 1148 This section defines cache response directives. A cache MUST obey 1149 the requirements of the Cache-Control directives defined in this 1150 section. 1152 5.2.2.1. must-revalidate 1154 The "must-revalidate" response directive indicates that once it has 1155 become stale, the response MUST NOT be used to satisfy any other 1156 request without forwarding it for validation and receiving a 1157 successful response; see Section 4.3. 1159 The must-revalidate directive is necessary to support reliable 1160 operation for certain protocol features. In all circumstances a 1161 cache MUST obey the must-revalidate directive; in particular, if a 1162 cache is disconnected, it MUST generate a 504 (Gateway Timeout) 1163 response. 1165 The must-revalidate directive ought to be used by servers if and only 1166 if failure to validate a request on the representation could result 1167 in incorrect operation, such as a silently unexecuted financial 1168 transaction. 1170 The must-revalidate directive also has the effect of allowing a 1171 stored response to be used to satisfy a request with an Authorization 1172 header field; see Section 3.2. 1174 5.2.2.2. no-cache 1176 Argument syntax: 1178 #field-name 1180 The "no-cache" response directive indicates that the response MUST 1181 NOT be used to satisfy any other request without forwarding it for 1182 validation and receiving a successful response; see Section 4.3. 1184 This allows an origin server to prevent a cache from using it to 1185 satisfy a request without contacting it, even by caches that have 1186 been configured to send stale responses. 1188 If the no-cache response directive specifies one or more field-names, 1189 then a cache MAY use the response to satisfy a subsequent request, 1190 subject to any other restrictions on caching. However, any header 1191 fields in the response that have the field-name(s) listed MUST NOT be 1192 sent in the response to a subsequent request without successful 1193 revalidation with the origin server. This allows an origin server to 1194 prevent the re-use of certain header fields in a response, while 1195 still allowing caching of the rest of the response. 1197 The field-names given are not limited to the set of header fields 1198 defined by this specification. Field names are case-insensitive. 1200 This directive uses the quoted-string form of the argument syntax. A 1201 sender SHOULD NOT generate the token form (even if quoting appears 1202 not to be needed for single-entry lists). 1204 Note: Although it has been back-ported to many implementations, some 1205 HTTP/1.0 caches will not recognize or obey this directive. Also, no- 1206 cache response directives with field-names are often handled by 1207 caches as if an unqualified no-cache directive was received; i.e., 1208 the special handling for the qualified form is not widely 1209 implemented. 1211 5.2.2.3. no-store 1213 The "no-store" response directive indicates that a cache MUST NOT 1214 store any part of either the immediate request or response, and MUST 1215 NOT use the response to satisfy any other request. 1217 This directive applies to both private and shared caches. "MUST NOT 1218 store" in this context means that the cache MUST NOT intentionally 1219 store the information in non-volatile storage, and MUST make a best- 1220 effort attempt to remove the information from volatile storage as 1221 promptly as possible after forwarding it. 1223 This directive is NOT a reliable or sufficient mechanism for ensuring 1224 privacy. In particular, malicious or compromised caches might not 1225 recognize or obey this directive, and communications networks might 1226 be vulnerable to eavesdropping. 1228 5.2.2.4. no-transform 1230 The "no-transform" response directive indicates that an intermediary 1231 (regardless of whether it implements a cache) MUST NOT transform the 1232 payload, as defined in Section 5.5.2 of [Semantics]. 1234 5.2.2.5. public 1236 The "public" response directive indicates that any cache MAY store 1237 the response, even if the response would normally be non-cacheable or 1238 cacheable only within a private cache. (See Section 3.2 for 1239 additional details related to the use of public in response to a 1240 request containing Authorization, and Section 3 for details of how 1241 public affects responses that would normally not be stored, due to 1242 their status codes not being defined as heuristically cacheable; see 1243 Section 4.2.2.) 1245 5.2.2.6. private 1247 Argument syntax: 1249 #field-name 1251 The "private" response directive indicates that the response message 1252 is intended for a single user and MUST NOT be stored by a shared 1253 cache. A private cache MAY store the response and reuse it for later 1254 requests, even if the response would normally be non-cacheable. 1256 If the private response directive specifies one or more field-names, 1257 this requirement is limited to the field-values associated with the 1258 listed response header fields. That is, a shared cache MUST NOT 1259 store the specified field-names(s), whereas it MAY store the 1260 remainder of the response message. 1262 The field-names given are not limited to the set of header fields 1263 defined by this specification. Field names are case-insensitive. 1265 This directive uses the quoted-string form of the argument syntax. A 1266 sender SHOULD NOT generate the token form (even if quoting appears 1267 not to be needed for single-entry lists). 1269 Note: This usage of the word "private" only controls where the 1270 response can be stored; it cannot ensure the privacy of the message 1271 content. Also, private response directives with field-names are 1272 often handled by caches as if an unqualified private directive was 1273 received; i.e., the special handling for the qualified form is not 1274 widely implemented. 1276 5.2.2.7. proxy-revalidate 1278 The "proxy-revalidate" response directive has the same meaning as the 1279 must-revalidate response directive, except that it does not apply to 1280 private caches. 1282 5.2.2.8. max-age 1284 Argument syntax: 1286 delta-seconds (see Section 1.3) 1288 The "max-age" response directive indicates that the response is to be 1289 considered stale after its age is greater than the specified number 1290 of seconds. 1292 This directive uses the token form of the argument syntax: e.g., 1293 'max-age=5' not 'max-age="5"'. A sender SHOULD NOT generate the 1294 quoted-string form. 1296 5.2.2.9. s-maxage 1298 Argument syntax: 1300 delta-seconds (see Section 1.3) 1302 The "s-maxage" response directive indicates that, in shared caches, 1303 the maximum age specified by this directive overrides the maximum age 1304 specified by either the max-age directive or the Expires header 1305 field. The s-maxage directive also implies the semantics of the 1306 proxy-revalidate response directive. 1308 The must-revalidate directive also has the effect of allowing a 1309 stored response to be used to satisfy a request with an Authorization 1310 header field; see Section 3.2. 1312 This directive uses the token form of the argument syntax: e.g., 1313 's-maxage=10' not 's-maxage="10"'. A sender SHOULD NOT generate the 1314 quoted-string form. 1316 5.2.3. Cache Control Extensions 1318 The Cache-Control header field can be extended through the use of one 1319 or more cache-extension tokens, each with an optional value. A cache 1320 MUST ignore unrecognized cache directives. 1322 Informational extensions (those that do not require a change in cache 1323 behavior) can be added without changing the semantics of other 1324 directives. 1326 Behavioral extensions are designed to work by acting as modifiers to 1327 the existing base of cache directives. Both the new directive and 1328 the old directive are supplied, such that applications that do not 1329 understand the new directive will default to the behavior specified 1330 by the old directive, and those that understand the new directive 1331 will recognize it as modifying the requirements associated with the 1332 old directive. In this way, extensions to the existing cache-control 1333 directives can be made without breaking deployed caches. 1335 For example, consider a hypothetical new response directive called 1336 "community" that acts as a modifier to the private directive: in 1337 addition to private caches, any cache that is shared only by members 1338 of the named community is allowed to cache the response. An origin 1339 server wishing to allow the UCI community to use an otherwise private 1340 response in their shared cache(s) could do so by including 1342 Cache-Control: private, community="UCI" 1344 A cache that recognizes such a community cache-extension could 1345 broaden its behavior in accordance with that extension. A cache that 1346 does not recognize the community cache-extension would ignore it and 1347 adhere to the private directive. 1349 New extension directives ought to consider defining: 1351 o What it means for a directive to be specified multiple times, 1353 o When the directive does not take an argument, what it means when 1354 an argument is present, 1356 o When the directive requires an argument, what it means when it is 1357 missing, 1359 o Whether the directive is specific to requests, responses, or able 1360 to be used in either. 1362 5.2.4. Cache Directive Registry 1364 The "Hypertext Transfer Protocol (HTTP) Cache Directive Registry" 1365 defines the namespace for the cache directives. It has been created 1366 and is now maintained at . 1369 A registration MUST include the following fields: 1371 o Cache Directive Name 1373 o Pointer to specification text 1375 Values to be added to this namespace require IETF Review (see 1376 [RFC8126], Section 4.8). 1378 5.3. Expires 1380 The "Expires" header field gives the date/time after which the 1381 response is considered stale. See Section 4.2 for further discussion 1382 of the freshness model. 1384 The presence of an Expires field does not imply that the original 1385 resource will change or cease to exist at, before, or after that 1386 time. 1388 The Expires value is an HTTP-date timestamp, as defined in 1389 Section 10.1.1.1 of [Semantics]. 1391 Expires = HTTP-date 1393 For example 1395 Expires: Thu, 01 Dec 1994 16:00:00 GMT 1397 A cache recipient MUST interpret invalid date formats, especially the 1398 value "0", as representing a time in the past (i.e., "already 1399 expired"). 1401 If a response includes a Cache-Control field with the max-age 1402 directive (Section 5.2.2.8), a recipient MUST ignore the Expires 1403 field. Likewise, if a response includes the s-maxage directive 1404 (Section 5.2.2.9), a shared cache recipient MUST ignore the Expires 1405 field. In both these cases, the value in Expires is only intended 1406 for recipients that have not yet implemented the Cache-Control field. 1408 An origin server without a clock MUST NOT generate an Expires field 1409 unless its value represents a fixed time in the past (always expired) 1410 or its value has been associated with the resource by a system or 1411 user with a reliable clock. 1413 Historically, HTTP required the Expires field-value to be no more 1414 than a year in the future. While longer freshness lifetimes are no 1415 longer prohibited, extremely large values have been demonstrated to 1416 cause problems (e.g., clock overflows due to use of 32-bit integers 1417 for time values), and many caches will evict a response far sooner 1418 than that. 1420 5.4. Pragma 1422 The "Pragma" header field was defined for HTTP/1.0 caches, so that 1423 clients could specify a "no-cache" request (as Cache-Control was not 1424 defined until HTTP/1.1). 1426 However, support for Cache-Control is now widespread. As a result, 1427 this specification deprecates Pragma. 1429 Note: Because the meaning of "Pragma: no-cache" in responses was 1430 never specified, it does not provide a reliable replacement for 1431 "Cache-Control: no-cache" in them. 1433 5.5. Warning 1435 The "Warning" header field was used to carry additional information 1436 about the status or transformation of a message that might not be 1437 reflected in the status code. This specification obsoletes it, as it 1438 is not widely generated or surfaced to users. The information it 1439 carried can be gleaned from examining other header fields, such as 1440 Age. 1442 6. Relationship to Applications 1444 Applications using HTTP often specify additional forms of caching. 1445 For example, Web browsers often have history mechanisms such as 1446 "Back" buttons that can be used to redisplay a representation 1447 retrieved earlier in a session. 1449 Likewise, some Web browsers implement caching of images and other 1450 assets within a page view; they may or may not honor HTTP caching 1451 semantics. 1453 The requirements in this specification do not necessarily apply to 1454 how applications use data after it is retrieved from a HTTP cache. 1455 That is, a history mechanism can display a previous representation 1456 even if it has expired, and an application can use cached data in 1457 other ways beyond its freshness lifetime. 1459 This does not prohibit the application from taking HTTP caching into 1460 account; for example, a history mechanism might tell the user that a 1461 view is stale, or it might honor cache directives (e.g., Cache- 1462 Control: no-store). 1464 7. Security Considerations 1466 This section is meant to inform developers, information providers, 1467 and users of known security concerns specific to HTTP caching. More 1468 general security considerations are addressed in HTTP messaging 1469 [Messaging] and semantics [Semantics]. 1471 Caches expose additional potential vulnerabilities, since the 1472 contents of the cache represent an attractive target for malicious 1473 exploitation. Because cache contents persist after an HTTP request 1474 is complete, an attack on the cache can reveal information long after 1475 a user believes that the information has been removed from the 1476 network. Therefore, cache contents need to be protected as sensitive 1477 information. 1479 7.1. Cache Poisoning 1481 Various attacks might be amplified by being stored in a shared cache. 1482 Such "cache poisoning" attacks use the cache to distribute a 1483 malicious payload to many clients, and are especially effective when 1484 an attacker can use implementation flaws, elevated privileges, or 1485 other techniques to insert such a response into a cache. 1487 One common attack vector for cache poisoning is to exploit 1488 differences in message parsing on proxies and in user agents; see 1489 Section 6.3 of [Messaging] for the relevant requirements regarding 1490 HTTP/1.1. 1492 7.2. Timing Attacks 1494 Because one of the primary uses of a cache is to optimise 1495 performance, its use can "leak" information about what resources have 1496 been previously requested. 1498 For example, if a user visits a site and their browser caches some of 1499 its responses, and then navigates to a second site, that site can 1500 attempt to load responses that it knows exists on the first site. If 1501 they load very quickly, it can be assumed that the user has visited 1502 that site, or even a specific page on it. 1504 Such "timing attacks" can be mitigated by adding more information to 1505 the cache key, such as the identity of the referring site (to prevent 1506 the attack described above). This is sometimes called "double 1507 keying." 1509 7.3. Caching of Sensitive Information 1511 Implementation and deployment flaws (as well as misunderstanding of 1512 cache operation) might lead to caching of sensitive information 1513 (e.g., authentication credentials) that is thought to be private, 1514 exposing it to unauthorized parties. 1516 Note that the Set-Cookie response header field [RFC6265] does not 1517 inhibit caching; a cacheable response with a Set-Cookie header field 1518 can be (and often is) used to satisfy subsequent requests to caches. 1519 Servers who wish to control caching of these responses are encouraged 1520 to emit appropriate Cache-Control response header fields. 1522 8. IANA Considerations 1524 The change controller for the following registrations is: "IETF 1525 (iesg@ietf.org) - Internet Engineering Task Force". 1527 8.1. Header Field Registration 1529 Please update the "Hypertext Transfer Protocol (HTTP) Header Field 1530 Registry" registry at 1531 with the header field names listed in the two tables of Section 5. 1533 8.2. Cache Directive Registration 1535 Please update the "Hypertext Transfer Protocol (HTTP) Cache Directive 1536 Registry" at 1537 with the registration procedure of Section 5.2.4 and the cache 1538 directive names summarized in the table of Section 5.2. 1540 8.3. Warn Code Registry 1542 Please add a note to the "Hypertext Transfer Protocol (HTTP) Warn 1543 Codes" registry at 1544 to the effect that Warning is obsoleted. 1546 9. References 1548 9.1. Normative References 1550 [Messaging] 1551 Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, 1552 Ed., "HTTP/1.1 Messaging", draft-ietf-httpbis-messaging-06 1553 (work in progress), November 2019. 1555 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1556 Requirement Levels", BCP 14, RFC 2119, 1557 DOI 10.17487/RFC2119, March 1997, 1558 . 1560 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 1561 Resource Identifier (URI): Generic Syntax", STD 66, 1562 RFC 3986, DOI 10.17487/RFC3986, January 2005, 1563 . 1565 [RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax 1566 Specifications: ABNF", STD 68, RFC 5234, 1567 DOI 10.17487/RFC5234, January 2008, 1568 . 1570 [RFC7405] Kyzivat, P., "Case-Sensitive String Support in ABNF", 1571 RFC 7405, DOI 10.17487/RFC7405, December 2014, 1572 . 1574 [Semantics] 1575 Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, 1576 Ed., "HTTP Semantics", draft-ietf-httpbis-semantics-06 1577 (work in progress), November 2019. 1579 [USASCII] American National Standards Institute, "Coded Character 1580 Set -- 7-bit American Standard Code for Information 1581 Interchange", ANSI X3.4, 1986. 1583 9.2. Informative References 1585 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 1586 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 1587 Transfer Protocol -- HTTP/1.1", RFC 2616, 1588 DOI 10.17487/RFC2616, June 1999, 1589 . 1591 [RFC5861] Nottingham, M., "HTTP Cache-Control Extensions for Stale 1592 Content", RFC 5861, DOI 10.17487/RFC5861, April 2010, 1593 . 1595 [RFC5905] Mills, D., Martin, J., Ed., Burbank, J., and W. Kasch, 1596 "Network Time Protocol Version 4: Protocol and Algorithms 1597 Specification", RFC 5905, DOI 10.17487/RFC5905, June 2010, 1598 . 1600 [RFC6265] Barth, A., "HTTP State Management Mechanism", RFC 6265, 1601 DOI 10.17487/RFC6265, April 2011, 1602 . 1604 [RFC7234] Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, 1605 Ed., "Hypertext Transfer Protocol (HTTP): Caching", 1606 RFC 7234, DOI 10.17487/RFC7234, June 2014, 1607 . 1609 [RFC8126] Cotton, M., Leiba, B., and T. Narten, "Guidelines for 1610 Writing an IANA Considerations Section in RFCs", BCP 26, 1611 RFC 8126, DOI 10.17487/RFC8126, June 2017, 1612 . 1614 Appendix A. Collected ABNF 1616 In the collected ABNF below, list rules are expanded as per 1617 Section 12 of [Semantics]. 1619 Age = delta-seconds 1621 Cache-Control = [ cache-directive ] *( OWS "," OWS [ cache-directive 1622 ] ) 1624 Expires = HTTP-date 1626 HTTP-date = 1628 OWS = 1630 cache-directive = token [ "=" ( token / quoted-string ) ] 1632 delta-seconds = 1*DIGIT 1634 field-name = 1636 quoted-string = 1638 token = 1640 Appendix B. Changes from RFC 7234 1642 The Warning response header was obsoleted. Much of the information 1643 supported by Warning could be gleaned by examining the response), and 1644 the remaining warn-codes -- although potentially useful -- were 1645 entirely advisory, and in practice were not added by caches or 1646 intermediaries. (Section 5.5) 1648 Appendix C. Change Log 1650 This section is to be removed before publishing as an RFC. 1652 C.1. Between RFC7234 and draft 00 1654 The changes were purely editorial: 1656 o Change boilerplate and abstract to indicate the "draft" status, 1657 and update references to ancestor specifications. 1659 o Remove version "1.1" from document title, indicating that this 1660 specification applies to all HTTP versions. 1662 o Adjust historical notes. 1664 o Update links to sibling specifications. 1666 o Replace sections listing changes from RFC 2616 by new empty 1667 sections referring to RFC 723x. 1669 o Remove acknowledgements specific to RFC 723x. 1671 o Move "Acknowledgements" to the very end and make them unnumbered. 1673 C.2. Since draft-ietf-httpbis-cache-00 1675 The changes are purely editorial: 1677 o Moved all extensibility tips, registration procedures, and 1678 registry tables from the IANA considerations to normative 1679 sections, reducing the IANA considerations to just instructions 1680 that will be removed prior to publication as an RFC. 1682 C.3. Since draft-ietf-httpbis-cache-01 1684 o Cite RFC 8126 instead of RFC 5226 () 1687 o In Section 5.4, misleading statement about the relation between 1688 Pragma and Cache-Control (, ) 1691 C.4. Since draft-ietf-httpbis-cache-02 1693 o In Section 3, explain that only final responses are cacheable 1694 () 1696 o In Section 5.2.2, clarify what responses various directives apply 1697 to () 1699 o In Section 4.3.1, clarify the source of validators in conditional 1700 requests () 1702 o Revise Section 6 to apply to more than just History Lists 1703 () 1705 o In Section 5.5, deprecated "Warning" header field 1706 () 1708 o In Section 3.2, remove a spurious note 1709 () 1711 C.5. Since draft-ietf-httpbis-cache-03 1713 o In Section 2, define what a disconnected cache is 1714 () 1716 o In Section 4, clarify language around how to select a response 1717 when more than one matches () 1720 o in Section 4.2.4, mention stale-while-revalidate and stale-if- 1721 error () 1723 o Remove requirements around cache request directives 1724 () 1726 o Deprecate Pragma () 1729 o In Section 3.2 and Section 5.2.2, note effect of some directives 1730 on authenticated requests () 1733 C.6. Since draft-ietf-httpbis-cache-04 1735 o In Section 5.2, remove the registrations for stale-if-error and 1736 stale-while-revalidate which happened in RFC 7234 1737 () 1739 C.7. Since draft-ietf-httpbis-cache-05 1741 o In Section 3.1, clarify how weakly framed content is considered 1742 for purposes of completeness () 1745 o Througout, describe Vary and cache key operations more clearly 1746 () 1748 o In Section 3, remove concept of "cacheable methods" in favor of 1749 prose () 1751 o Refactored Section 7, and added a section on timing attacks 1752 () 1754 o Changed "cacheable by default" to "heuristically cacheable" 1755 throughout () 1757 Index 1759 A 1760 Age header field 21 1761 age 12 1763 C 1764 Cache-Control header field 22 1765 cache 4 1766 cache key 6 1768 E 1769 Expires header field 30 1770 explicit expiration time 12 1772 F 1773 fresh 12 1774 freshness lifetime 12 1776 G 1777 Grammar 1778 Age 21 1779 ALPHA 5 1780 Cache-Control 22 1781 cache-directive 22 1782 CR 5 1783 CRLF 5 1784 CTL 5 1785 delta-seconds 6 1786 DIGIT 5 1787 DQUOTE 5 1788 Expires 30 1789 HEXDIG 5 1790 HTAB 5 1791 LF 5 1792 OCTET 5 1793 SP 5 1794 VCHAR 5 1796 H 1797 heuristic expiration time 12 1798 heuristically cacheable 14 1800 M 1801 max-age (cache directive) 23, 28 1802 max-stale (cache directive) 23 1803 min-fresh (cache directive) 24 1804 must-revalidate (cache directive) 25 1806 N 1807 no-cache (cache directive) 24, 26 1808 no-store (cache directive) 24, 26 1809 no-transform (cache directive) 25, 27 1811 O 1812 only-if-cached (cache directive) 25 1814 P 1815 Pragma header field 31 1816 private (cache directive) 27 1817 private cache 4 1818 proxy-revalidate (cache directive) 28 1819 public (cache directive) 27 1821 S 1822 s-maxage (cache directive) 28 1823 shared cache 4 1824 stale 12 1825 strong validator 19 1827 V 1828 validator 16 1830 W 1831 Warning header field 31 1833 Acknowledgments 1835 See Appendix "Acknowledgments" of [Semantics]. 1837 Authors' Addresses 1839 Roy T. Fielding (editor) 1840 Adobe 1841 345 Park Ave 1842 San Jose, CA 95110 1843 United States of America 1845 EMail: fielding@gbiv.com 1846 URI: https://roy.gbiv.com/ 1848 Mark Nottingham (editor) 1849 Fastly 1851 EMail: mnot@mnot.net 1852 URI: https://www.mnot.net/ 1853 Julian F. Reschke (editor) 1854 greenbytes GmbH 1855 Hafenweg 16 1856 Muenster 48155 1857 Germany 1859 EMail: julian.reschke@greenbytes.de 1860 URI: https://greenbytes.de/tech/webdav/