idnits 2.17.1 draft-ietf-httpbis-p4-conditional-21.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 : ---------------------------------------------------------------------------- -- The draft header indicates that this document obsoletes RFC2616, but the abstract doesn't seem to mention this, which it should. 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, and may have content which was first submitted before 10 November 2008. The disclaimer is necessary when there are original authors that you have been unable to contact, or if some do not wish to grant the BCP78 rights to the IETF Trust. If you are able to get all authors (current and original) to grant those rights, 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 (October 4, 2012) is 4222 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Outdated reference: A later version (-26) exists of draft-ietf-httpbis-p1-messaging-21 == Outdated reference: A later version (-26) exists of draft-ietf-httpbis-p2-semantics-21 == Outdated reference: A later version (-26) exists of draft-ietf-httpbis-p5-range-21 == Outdated reference: A later version (-26) exists of draft-ietf-httpbis-p6-cache-21 -- Obsolete informational reference (is this intentional?): RFC 2616 (Obsoleted by RFC 7230, RFC 7231, RFC 7232, RFC 7233, RFC 7234, RFC 7235) Summary: 0 errors (**), 0 flaws (~~), 5 warnings (==), 4 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 HTTPbis Working Group R. Fielding, Ed. 3 Internet-Draft Adobe 4 Obsoletes: 2616 (if approved) J. Reschke, Ed. 5 Intended status: Standards Track greenbytes 6 Expires: April 7, 2013 October 4, 2012 8 Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests 9 draft-ietf-httpbis-p4-conditional-21 11 Abstract 13 The Hypertext Transfer Protocol (HTTP) is an application-level 14 protocol for distributed, collaborative, hypertext information 15 systems. This document defines HTTP/1.1 conditional requests, 16 including metadata header fields for indicating state changes, 17 request header fields for making preconditions on such state, and 18 rules for constructing the responses to a conditional request when 19 one or more preconditions evaluate to false. 21 Editorial Note (To be removed by RFC Editor) 23 Discussion of this draft takes place on the HTTPBIS working group 24 mailing list (ietf-http-wg@w3.org), which is archived at 25 . 27 The current issues list is at 28 and related 29 documents (including fancy diffs) can be found at 30 . 32 The changes in this draft are summarized in Appendix D.2. 34 Status of This Memo 36 This Internet-Draft is submitted in full conformance with the 37 provisions of BCP 78 and BCP 79. 39 Internet-Drafts are working documents of the Internet Engineering 40 Task Force (IETF). Note that other groups may also distribute 41 working documents as Internet-Drafts. The list of current Internet- 42 Drafts is at http://datatracker.ietf.org/drafts/current/. 44 Internet-Drafts are draft documents valid for a maximum of six months 45 and may be updated, replaced, or obsoleted by other documents at any 46 time. It is inappropriate to use Internet-Drafts as reference 47 material or to cite them other than as "work in progress." 48 This Internet-Draft will expire on April 7, 2013. 50 Copyright Notice 52 Copyright (c) 2012 IETF Trust and the persons identified as the 53 document authors. All rights reserved. 55 This document is subject to BCP 78 and the IETF Trust's Legal 56 Provisions Relating to IETF Documents 57 (http://trustee.ietf.org/license-info) in effect on the date of 58 publication of this document. Please review these documents 59 carefully, as they describe your rights and restrictions with respect 60 to this document. Code Components extracted from this document must 61 include Simplified BSD License text as described in Section 4.e of 62 the Trust Legal Provisions and are provided without warranty as 63 described in the Simplified BSD License. 65 This document may contain material from IETF Documents or IETF 66 Contributions published or made publicly available before November 67 10, 2008. The person(s) controlling the copyright in some of this 68 material may not have granted the IETF Trust the right to allow 69 modifications of such material outside the IETF Standards Process. 70 Without obtaining an adequate license from the person(s) controlling 71 the copyright in such materials, this document may not be modified 72 outside the IETF Standards Process, and derivative works of it may 73 not be created outside the IETF Standards Process, except to format 74 it for publication as an RFC or to translate it into languages other 75 than English. 77 Table of Contents 79 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 4 80 1.1. Conformance and Error Handling . . . . . . . . . . . . . . 4 81 1.2. Syntax Notation . . . . . . . . . . . . . . . . . . . . . 5 82 2. Validators . . . . . . . . . . . . . . . . . . . . . . . . . . 5 83 2.1. Weak versus Strong . . . . . . . . . . . . . . . . . . . . 5 84 2.2. Last-Modified . . . . . . . . . . . . . . . . . . . . . . 7 85 2.2.1. Generation . . . . . . . . . . . . . . . . . . . . . . 7 86 2.2.2. Comparison . . . . . . . . . . . . . . . . . . . . . . 8 87 2.3. ETag . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 88 2.3.1. Generation . . . . . . . . . . . . . . . . . . . . . . 10 89 2.3.2. Comparison . . . . . . . . . . . . . . . . . . . . . . 10 90 2.3.3. Example: Entity-tags varying on Content-Negotiated 91 Resources . . . . . . . . . . . . . . . . . . . . . . 11 92 2.4. Rules for When to Use Entity-tags and Last-Modified 93 Dates . . . . . . . . . . . . . . . . . . . . . . . . . . 12 94 3. Precondition Header Fields . . . . . . . . . . . . . . . . . . 13 95 3.1. If-Match . . . . . . . . . . . . . . . . . . . . . . . . . 13 96 3.2. If-None-Match . . . . . . . . . . . . . . . . . . . . . . 14 97 3.3. If-Modified-Since . . . . . . . . . . . . . . . . . . . . 16 98 3.4. If-Unmodified-Since . . . . . . . . . . . . . . . . . . . 17 99 3.5. If-Range . . . . . . . . . . . . . . . . . . . . . . . . . 17 100 4. Status Code Definitions . . . . . . . . . . . . . . . . . . . 18 101 4.1. 304 Not Modified . . . . . . . . . . . . . . . . . . . . . 18 102 4.2. 412 Precondition Failed . . . . . . . . . . . . . . . . . 18 103 5. Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . 19 104 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 20 105 6.1. Status Code Registration . . . . . . . . . . . . . . . . . 20 106 6.2. Header Field Registration . . . . . . . . . . . . . . . . 20 107 7. Security Considerations . . . . . . . . . . . . . . . . . . . 21 108 8. Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . 21 109 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 21 110 9.1. Normative References . . . . . . . . . . . . . . . . . . . 21 111 9.2. Informative References . . . . . . . . . . . . . . . . . . 22 112 Appendix A. Changes from RFC 2616 . . . . . . . . . . . . . . . . 22 113 Appendix B. Imported ABNF . . . . . . . . . . . . . . . . . . . . 22 114 Appendix C. Collected ABNF . . . . . . . . . . . . . . . . . . . 23 115 Appendix D. Change Log (to be removed by RFC Editor before 116 publication) . . . . . . . . . . . . . . . . . . . . 23 117 D.1. Since draft-ietf-httpbis-p4-conditional-19 . . . . . . . . 23 118 D.2. Since draft-ietf-httpbis-p4-conditional-20 . . . . . . . . 24 119 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 121 1. Introduction 123 Conditional requests are HTTP requests [Part2] that include one or 124 more header fields indicating a precondition to be tested before 125 applying the method semantics to the target resource. Each 126 precondition is based on metadata that is expected to change if the 127 selected representation of the target resource is changed. This 128 document defines the HTTP/1.1 conditional request mechanisms in terms 129 of the architecture, syntax notation, and conformance criteria 130 defined in [Part1]. 132 Conditional GET requests are the most efficient mechanism for HTTP 133 cache updates [Part6]. Conditionals can also be applied to state- 134 changing methods, such as PUT and DELETE, to prevent the "lost 135 update" problem: one client accidentally overwriting the work of 136 another client that has been acting in parallel. 138 Conditional request preconditions are based on the state of the 139 target resource as a whole (its current value set) or the state as 140 observed in a previously obtained representation (one value in that 141 set). A resource might have multiple current representations, each 142 with its own observable state. The conditional request mechanisms 143 assume that the mapping of requests to corresponding representations 144 will be consistent over time if the server intends to take advantage 145 of conditionals. Regardless, if the mapping is inconsistent and the 146 server is unable to select the appropriate representation, then no 147 harm will result when the precondition evaluates to false. 149 We use the term "selected representation" to refer to the current 150 representation of the target resource that would have been selected 151 in a successful response if the same request had used the method GET 152 and had excluded all of the conditional request header fields. The 153 conditional request preconditions are evaluated by comparing the 154 values provided in the request header fields to the current metadata 155 for the selected representation. 157 1.1. Conformance and Error Handling 159 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 160 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 161 document are to be interpreted as described in [RFC2119]. 163 Conformance criteria and considerations regarding error handling are 164 defined in Section 2.5 of [Part1]. 166 1.2. Syntax Notation 168 This specification uses the Augmented Backus-Naur Form (ABNF) 169 notation of [RFC5234] with the list rule extension defined in Section 170 1.2 of [Part1]. Appendix B describes rules imported from other 171 documents. Appendix C shows the collected ABNF with the list rule 172 expanded. 174 2. Validators 176 This specification defines two forms of metadata that are commonly 177 used to observe resource state and test for preconditions: 178 modification dates (Section 2.2) and opaque entity tags 179 (Section 2.3). Additional metadata that reflects resource state has 180 been defined by various extensions of HTTP, such as WebDAV [RFC4918], 181 that are beyond the scope of this specification. A resource metadata 182 value is referred to as a "validator" when it is used within a 183 precondition. 185 2.1. Weak versus Strong 187 Validators come in two flavors: strong or weak. Weak validators are 188 easy to generate but are far less useful for comparisons. Strong 189 validators are ideal for comparisons but can be very difficult (and 190 occasionally impossible) to generate efficiently. Rather than impose 191 that all forms of resource adhere to the same strength of validator, 192 HTTP exposes the type of validator in use and imposes restrictions on 193 when weak validators can be used as preconditions. 195 A "strong validator" is a representation metadata value that MUST be 196 changed to a new, previously unused or guaranteed unique, value 197 whenever a change occurs to the representation data such that a 198 change would be observable in the payload body of a 200 (OK) response 199 to GET. 201 A strong validator MAY be changed for other reasons, such as when a 202 semantically significant part of the representation metadata is 203 changed (e.g., Content-Type), but it is in the best interests of the 204 origin server to only change the value when it is necessary to 205 invalidate the stored responses held by remote caches and authoring 206 tools. A strong validator MUST be unique across all representations 207 of a given resource, such that no two representations of that 208 resource share the same validator unless their payload body would be 209 identical. 211 Cache entries might persist for arbitrarily long periods, regardless 212 of expiration times. Thus, a cache might attempt to validate an 213 entry using a validator that it obtained in the distant past. A 214 strong validator MUST be unique across all versions of all 215 representations associated with a particular resource over time. 216 However, there is no implication of uniqueness across representations 217 of different resources (i.e., the same strong validator might be in 218 use for representations of multiple resources at the same time and 219 does not imply that those representations are equivalent). 221 There are a variety of strong validators used in practice. The best 222 are based on strict revision control, wherein each change to a 223 representation always results in a unique node name and revision 224 identifier being assigned before the representation is made 225 accessible to GET. A collision-resistant hash function applied to 226 the representation data is also sufficient if the data is available 227 prior to the response header fields being sent and the digest does 228 not need to be recalculated every time a validation request is 229 received. However, if a resource has distinct representations that 230 differ only in their metadata, such as might occur with content 231 negotiation over media types that happen to share the same data 232 format, then the origin server SHOULD incorporate additional 233 information in the validator to distinguish those representations and 234 avoid confusing cache behavior. 236 In contrast, a "weak validator" is a representation metadata value 237 that might not be changed for every change to the representation 238 data. This weakness might be due to limitations in how the value is 239 calculated, such as clock resolution or an inability to ensure 240 uniqueness for all possible representations of the resource, or due 241 to a desire by the resource owner to group representations by some 242 self-determined set of equivalency rather than unique sequences of 243 data. An origin server SHOULD change a weak entity-tag whenever it 244 considers prior representations to be unacceptable as a substitute 245 for the current representation. In other words, a weak entity-tag 246 ought to change whenever the origin server wants caches to invalidate 247 old responses. 249 For example, the representation of a weather report that changes in 250 content every second, based on dynamic measurements, might be grouped 251 into sets of equivalent representations (from the origin server's 252 perspective) with the same weak validator in order to allow cached 253 representations to be valid for a reasonable period of time (perhaps 254 adjusted dynamically based on server load or weather quality). 255 Likewise, a representation's modification time, if defined with only 256 one-second resolution, might be a weak validator if it is possible 257 for the representation to be modified twice during a single second 258 and retrieved between those modifications. 260 A "use" of a validator occurs when either a client generates a 261 request and includes the validator in a precondition or when a server 262 compares two validators. Weak validators are only usable in contexts 263 that do not depend on exact equality of a representation's payload 264 body. Strong validators are usable and preferred for all conditional 265 requests, including cache validation, partial content ranges, and 266 "lost update" avoidance. 268 2.2. Last-Modified 270 The "Last-Modified" header field indicates the date and time at which 271 the origin server believes the selected representation was last 272 modified. 274 Last-Modified = HTTP-date 276 An example of its use is 278 Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT 280 2.2.1. Generation 282 Origin servers SHOULD send Last-Modified for any selected 283 representation for which a last modification date can be reasonably 284 and consistently determined, since its use in conditional requests 285 and evaluating cache freshness ([Part6]) results in a substantial 286 reduction of HTTP traffic on the Internet and can be a significant 287 factor in improving service scalability and reliability. 289 A representation is typically the sum of many parts behind the 290 resource interface. The last-modified time would usually be the most 291 recent time that any of those parts were changed. How that value is 292 determined for any given resource is an implementation detail beyond 293 the scope of this specification. What matters to HTTP is how 294 recipients of the Last-Modified header field can use its value to 295 make conditional requests and test the validity of locally cached 296 responses. 298 An origin server SHOULD obtain the Last-Modified value of the 299 representation as close as possible to the time that it generates the 300 Date field value for its response. This allows a recipient to make 301 an accurate assessment of the representation's modification time, 302 especially if the representation changes near the time that the 303 response is generated. 305 An origin server with a clock MUST NOT send a Last-Modified date that 306 is later than the server's time of message origination (Date). If 307 the last modification time is derived from implementation-specific 308 metadata that evaluates to some time in the future, according to the 309 origin server's clock, then the origin server MUST replace that value 310 with the message origination date. This prevents a future 311 modification date from having an adverse impact on cache validation. 313 An origin server without a clock MUST NOT assign Last-Modified values 314 to a response unless these values were associated with the resource 315 by some other system or user with a reliable clock. 317 2.2.2. Comparison 319 A Last-Modified time, when used as a validator in a request, is 320 implicitly weak unless it is possible to deduce that it is strong, 321 using the following rules: 323 o The validator is being compared by an origin server to the actual 324 current validator for the representation and, 326 o That origin server reliably knows that the associated 327 representation did not change twice during the second covered by 328 the presented validator. 330 or 332 o The validator is about to be used by a client in an If-Modified- 333 Since, If-Unmodified-Since header field, because the client has a 334 cache entry, or If-Range for the associated representation, and 336 o That cache entry includes a Date value, which gives the time when 337 the origin server sent the original response, and 339 o The presented Last-Modified time is at least 60 seconds before the 340 Date value. 342 or 344 o The validator is being compared by an intermediate cache to the 345 validator stored in its cache entry for the representation, and 347 o That cache entry includes a Date value, which gives the time when 348 the origin server sent the original response, and 350 o The presented Last-Modified time is at least 60 seconds before the 351 Date value. 353 This method relies on the fact that if two different responses were 354 sent by the origin server during the same second, but both had the 355 same Last-Modified time, then at least one of those responses would 356 have a Date value equal to its Last-Modified time. The arbitrary 60- 357 second limit guards against the possibility that the Date and Last- 358 Modified values are generated from different clocks, or at somewhat 359 different times during the preparation of the response. An 360 implementation MAY use a value larger than 60 seconds, if it is 361 believed that 60 seconds is too short. 363 2.3. ETag 365 The "ETag" header field provides the current entity-tag for the 366 selected representation. An entity-tag is an opaque validator for 367 differentiating between multiple representations of the same 368 resource, regardless of whether those multiple representations are 369 due to resource state changes over time, content negotiation 370 resulting in multiple representations being valid at the same time, 371 or both. An entity-tag consists of an opaque quoted string, possibly 372 prefixed by a weakness indicator. 374 ETag = entity-tag 376 entity-tag = [ weak ] opaque-tag 377 weak = %x57.2F ; "W/", case-sensitive 378 opaque-tag = DQUOTE *etagc DQUOTE 379 etagc = %x21 / %x23-7E / obs-text 380 ; VCHAR except double quotes, plus obs-text 382 Note: Previously, opaque-tag was defined to be a quoted-string 383 ([RFC2616], Section 3.11), thus some recipients might perform 384 backslash unescaping. Servers therefore ought to avoid backslash 385 characters in entity tags. 387 An entity-tag can be more reliable for validation than a modification 388 date in situations where it is inconvenient to store modification 389 dates, where the one-second resolution of HTTP date values is not 390 sufficient, or where modification dates are not consistently 391 maintained. 393 Examples: 395 ETag: "xyzzy" 396 ETag: W/"xyzzy" 397 ETag: "" 399 An entity-tag can be either a weak or strong validator, with strong 400 being the default. If an origin server provides an entity-tag for a 401 representation and the generation of that entity-tag does not satisfy 402 the requirements for a strong validator (Section 2.1), then that 403 entity-tag MUST be marked as weak by prefixing its opaque value with 404 "W/" (case-sensitive). 406 2.3.1. Generation 408 The principle behind entity-tags is that only the service author 409 knows the implementation of a resource well enough to select the most 410 accurate and efficient validation mechanism for that resource, and 411 that any such mechanism can be mapped to a simple sequence of octets 412 for easy comparison. Since the value is opaque, there is no need for 413 the client to be aware of how each entity-tag is constructed. 415 For example, a resource that has implementation-specific versioning 416 applied to all changes might use an internal revision number, perhaps 417 combined with a variance identifier for content negotiation, to 418 accurately differentiate between representations. Other 419 implementations might use a collision-resistant hash of 420 representation content, a combination of various filesystem 421 attributes, or a modification timestamp that has sub-second 422 resolution. 424 Origin servers SHOULD send ETag for any selected representation for 425 which detection of changes can be reasonably and consistently 426 determined, since the entity-tag's use in conditional requests and 427 evaluating cache freshness ([Part6]) can result in a substantial 428 reduction of HTTP network traffic and can be a significant factor in 429 improving service scalability and reliability. 431 2.3.2. Comparison 433 There are two entity-tag comparison functions, depending on whether 434 the comparison context allows the use of weak validators or not: 436 o The strong comparison function: in order to be considered equal, 437 both opaque-tags MUST be identical character-by-character, and 438 both MUST NOT be weak. 440 o The weak comparison function: in order to be considered equal, 441 both opaque-tags MUST be identical character-by-character, but 442 either or both of them MAY be tagged as "weak" without affecting 443 the result. 445 The example below shows the results for a set of entity-tag pairs, 446 and both the weak and strong comparison function results: 448 +--------+--------+-------------------+-----------------+ 449 | ETag 1 | ETag 2 | Strong Comparison | Weak Comparison | 450 +--------+--------+-------------------+-----------------+ 451 | W/"1" | W/"1" | no match | match | 452 | W/"1" | W/"2" | no match | no match | 453 | W/"1" | "1" | no match | match | 454 | "1" | "1" | match | match | 455 +--------+--------+-------------------+-----------------+ 457 2.3.3. Example: Entity-tags varying on Content-Negotiated Resources 459 Consider a resource that is subject to content negotiation (Section 460 3.4 of [Part2]), and where the representations returned upon a GET 461 request vary based on the Accept-Encoding request header field 462 (Section 6.3.4 of [Part2]): 464 >> Request: 466 GET /index HTTP/1.1 467 Host: www.example.com 468 Accept-Encoding: gzip 470 In this case, the response might or might not use the gzip content 471 coding. If it does not, the response might look like: 473 >> Response: 475 HTTP/1.1 200 OK 476 Date: Thu, 26 Mar 2010 00:05:00 GMT 477 ETag: "123-a" 478 Content-Length: 70 479 Vary: Accept-Encoding 480 Content-Type: text/plain 482 Hello World! 483 Hello World! 484 Hello World! 485 Hello World! 486 Hello World! 488 An alternative representation that does use gzip content coding would 489 be: 491 >> Response: 493 HTTP/1.1 200 OK 494 Date: Thu, 26 Mar 2010 00:05:00 GMT 495 ETag: "123-b" 496 Content-Length: 43 497 Vary: Accept-Encoding 498 Content-Type: text/plain 499 Content-Encoding: gzip 501 ...binary data... 503 Note: Content codings are a property of the representation, so 504 therefore an entity-tag of an encoded representation has to be 505 distinct from an unencoded representation to prevent conflicts 506 during cache updates and range requests. In contrast, transfer 507 codings (Section 4 of [Part1]) apply only during message transfer 508 and do not require distinct entity-tags. 510 2.4. Rules for When to Use Entity-tags and Last-Modified Dates 512 We adopt a set of rules and recommendations for origin servers, 513 clients, and caches regarding when various validator types ought to 514 be used, and for what purposes. 516 HTTP/1.1 origin servers: 518 o SHOULD send an entity-tag validator unless it is not feasible to 519 generate one. 521 o MAY send a weak entity-tag instead of a strong entity-tag, if 522 performance considerations support the use of weak entity-tags, or 523 if it is unfeasible to send a strong entity-tag. 525 o SHOULD send a Last-Modified value if it is feasible to send one. 527 In other words, the preferred behavior for an HTTP/1.1 origin server 528 is to send both a strong entity-tag and a Last-Modified value. 530 HTTP/1.1 clients: 532 o MUST use that entity-tag in any cache-conditional request (using 533 If-Match or If-None-Match) if an entity-tag has been provided by 534 the origin server. 536 o SHOULD use the Last-Modified value in non-subrange cache- 537 conditional requests (using If-Modified-Since) if only a Last- 538 Modified value has been provided by the origin server. 540 o MAY use the Last-Modified value in subrange cache-conditional 541 requests (using If-Unmodified-Since) if only a Last-Modified value 542 has been provided by an HTTP/1.0 origin server. The user agent 543 SHOULD provide a way to disable this, in case of difficulty. 545 o SHOULD use both validators in cache-conditional requests if both 546 an entity-tag and a Last-Modified value have been provided by the 547 origin server. This allows both HTTP/1.0 and HTTP/1.1 caches to 548 respond appropriately. 550 An HTTP/1.1 origin server, upon receiving a conditional request that 551 includes both a Last-Modified date (e.g., in an If-Modified-Since or 552 If-Unmodified-Since header field) and one or more entity-tags (e.g., 553 in an If-Match, If-None-Match, or If-Range header field) as cache 554 validators, MUST NOT return a response status code of 304 (Not 555 Modified) unless doing so is consistent with all of the conditional 556 header fields in the request. 558 An HTTP/1.1 caching proxy, upon receiving a conditional request that 559 includes both a Last-Modified date and one or more entity-tags as 560 cache validators, MUST NOT return a locally cached response to the 561 client unless that cached response is consistent with all of the 562 conditional header fields in the request. 564 Note: The general principle behind these rules is that HTTP/1.1 565 servers and clients ought to transmit as much non-redundant 566 information as is available in their responses and requests. 567 HTTP/1.1 systems receiving this information will make the most 568 conservative assumptions about the validators they receive. 570 HTTP/1.0 clients and caches might ignore entity-tags. Generally, 571 last-modified values received or used by these systems will 572 support transparent and efficient caching, and so HTTP/1.1 origin 573 servers still ought to provide Last-Modified values. 575 3. Precondition Header Fields 577 This section defines the syntax and semantics of HTTP/1.1 header 578 fields for applying preconditions on requests. Section 5 defines the 579 order of evaluation when more than one precondition is present in a 580 request. 582 3.1. If-Match 584 The "If-Match" header field can be used to make a request method 585 conditional on the current existence or value of an entity-tag for 586 one or more representations of the target resource. 588 If-Match is generally useful for resource update requests, such as 589 PUT requests, as a means for protecting against accidental overwrites 590 when multiple clients are acting in parallel on the same resource 591 (i.e., the "lost update" problem). An If-Match field-value of "*" 592 places the precondition on the existence of any current 593 representation for the target resource. 595 If-Match = "*" / 1#entity-tag 597 The If-Match condition is met if and only if any of the entity-tags 598 listed in the If-Match field value match the entity-tag of the 599 selected representation for the target resource (as per 600 Section 2.3.2), or if "*" is given and any current representation 601 exists for the target resource. 603 If the condition is met, the server MAY perform the request method as 604 if the If-Match header field was not present. 606 Origin servers MUST NOT perform the requested method if the condition 607 is not met; instead they MUST respond with the 412 (Precondition 608 Failed) status code. 610 Proxy servers using a cached response as the selected representation 611 MUST NOT perform the requested method if the condition is not met; 612 instead, they MUST forward the request towards the origin server. 614 If the request would, without the If-Match header field, result in 615 anything other than a 2xx (Successful) or 412 (Precondition Failed) 616 status code, then the If-Match header field MUST be ignored. 618 Examples: 620 If-Match: "xyzzy" 621 If-Match: "xyzzy", "r2d2xxxx", "c3piozzzz" 622 If-Match: * 624 3.2. If-None-Match 626 The "If-None-Match" header field can be used to make a request method 627 conditional on not matching any of the current entity-tag values for 628 representations of the target resource. 630 If-None-Match is primarily used in conditional GET requests to enable 631 efficient updates of cached information with a minimum amount of 632 transaction overhead. A client that has one or more representations 633 previously obtained from the target resource can send If-None-Match 634 with a list of the associated entity-tags in the hope of receiving a 635 304 (Not Modified) response if at least one of those representations 636 matches the selected representation. 638 If-None-Match can also be used with a value of "*" to prevent an 639 unsafe request method (e.g., PUT) from inadvertently modifying an 640 existing representation of the target resource when the client 641 believes that the resource does not have a current representation. 642 This is a variation on the "lost update" problem that might arise if 643 more than one client attempts to create an initial representation for 644 the target resource. 646 If-None-Match = "*" / 1#entity-tag 648 The If-None-Match condition is met if and only if none of the entity- 649 tags listed in the If-None-Match field value match the entity-tag of 650 the selected representation for the target resource (as per 651 Section 2.3.2), or if "*" is given and no current representation 652 exists for that resource. 654 If the condition is not met, the server MUST NOT perform the 655 requested method. Instead, if the request method was GET or HEAD, 656 the server SHOULD respond with a 304 (Not Modified) status code, 657 including the cache-related header fields (particularly ETag) of the 658 selected representation that has a matching entity-tag. For all 659 other request methods, the server MUST respond with a 412 660 (Precondition Failed) status code. 662 If the condition is met, the server MAY perform the requested method 663 as if the If-None-Match header field did not exist, but MUST also 664 ignore any If-Modified-Since header field(s) in the request. That 665 is, if no entity-tags match, then the server MUST NOT return a 304 666 (Not Modified) response. 668 If the request would, without the If-None-Match header field, result 669 in anything other than a 2xx (Successful) or 304 (Not Modified) 670 status code, then the If-None-Match header field MUST be ignored. 671 (See Section 2.4 for a discussion of server behavior when both If- 672 Modified-Since and If-None-Match appear in the same request.) 674 Examples: 676 If-None-Match: "xyzzy" 677 If-None-Match: W/"xyzzy" 678 If-None-Match: "xyzzy", "r2d2xxxx", "c3piozzzz" 679 If-None-Match: W/"xyzzy", W/"r2d2xxxx", W/"c3piozzzz" 680 If-None-Match: * 682 3.3. If-Modified-Since 684 The "If-Modified-Since" header field can be used with GET or HEAD to 685 make the method conditional by modification date: if the selected 686 representation has not been modified since the time specified in this 687 field, then do not perform the request method; instead, respond as 688 detailed below. 690 If-Modified-Since = HTTP-date 692 An example of the field is: 694 If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT 696 A GET method with an If-Modified-Since header field and no Range 697 header field requests that the selected representation be transferred 698 only if it has been modified since the date given by the If-Modified- 699 Since header field. The algorithm for determining this includes the 700 following cases: 702 1. If the request would normally result in anything other than a 200 703 (OK) status code, or if the passed If-Modified-Since date is 704 invalid, the response is exactly the same as for a normal GET. A 705 date which is later than the server's current time is invalid. 707 2. If the selected representation has been modified since the If- 708 Modified-Since date, the response is exactly the same as for a 709 normal GET. 711 3. If the selected representation has not been modified since a 712 valid If-Modified-Since date, the server SHOULD return a 304 (Not 713 Modified) response. 715 The purpose of this feature is to allow efficient updates of cached 716 information with a minimum amount of transaction overhead. 718 Note: The Range header field modifies the meaning of If-Modified- 719 Since; see Section 5.4 of [Part5] for full details. 721 Note: If-Modified-Since times are interpreted by the server, whose 722 clock might not be synchronized with the client. 724 Note: When handling an If-Modified-Since header field, some 725 servers will use an exact date comparison function, rather than a 726 less-than function, for deciding whether to send a 304 (Not 727 Modified) response. To get best results when sending an If- 728 Modified-Since header field for cache validation, clients are 729 advised to use the exact date string received in a previous Last- 730 Modified header field whenever possible. 732 Note: If a client uses an arbitrary date in the If-Modified-Since 733 header field instead of a date taken from the Last-Modified header 734 field for the same request, the client needs to be aware that this 735 date is interpreted in the server's understanding of time. 736 Unsynchronized clocks and rounding problems, due to the different 737 encodings of time between the client and server, are concerns. 738 This includes the possibility of race conditions if the document 739 has changed between the time it was first requested and the If- 740 Modified-Since date of a subsequent request, and the possibility 741 of clock-skew-related problems if the If-Modified-Since date is 742 derived from the client's clock without correction to the server's 743 clock. Corrections for different time bases between client and 744 server are at best approximate due to network latency. 746 3.4. If-Unmodified-Since 748 The "If-Unmodified-Since" header field can be used to make a request 749 method conditional by modification date: if the selected 750 representation has been modified since the time specified in this 751 field, then the server MUST NOT perform the requested operation and 752 MUST instead respond with the 412 (Precondition Failed) status code. 753 If the selected representation has not been modified since the time 754 specified in this field, the server SHOULD perform the request method 755 as if the If-Unmodified-Since header field were not present. 757 If-Unmodified-Since = HTTP-date 759 An example of the field is: 761 If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT 763 If a request normally (i.e., in absence of the If-Unmodified-Since 764 header field) would result in anything other than a 2xx (Successful) 765 or 412 (Precondition Failed) status code, the If-Unmodified-Since 766 header field SHOULD be ignored. 768 If the specified date is invalid, the header field MUST be ignored. 770 3.5. If-Range 772 The "If-Range" header field provides a special conditional request 773 mechanism that is similar to If-Match and If-Unmodified-Since but 774 specific to HTTP range requests. If-Range is defined in Section 5.3 775 of [Part5]. 777 4. Status Code Definitions 779 4.1. 304 Not Modified 781 The 304 status code indicates that a conditional GET request has been 782 received and would have resulted in a 200 (OK) response if it were 783 not for the fact that the condition has evaluated to false. In other 784 words, there is no need for the server to transfer a representation 785 of the target resource because the client's request indicates that it 786 already has a valid representation, as indicated by the 304 response 787 header fields, and is therefore redirecting the client to make use of 788 that stored representation as if it were the payload of a 200 789 response. The 304 response MUST NOT contain a message-body, and thus 790 is always terminated by the first empty line after the header fields. 792 A 304 response MUST include a Date header field (Section 8.1.1.2 of 793 [Part2]) unless the origin server does not have a clock that can 794 provide a reasonable approximation of the current time. If a 200 795 (OK) response to the same request would have included any of the 796 header fields Cache-Control, Content-Location, ETag, Expires, or 797 Vary, then those same header fields MUST be sent in a 304 response. 799 Since the goal of a 304 response is to minimize information transfer 800 when the recipient already has one or more cached representations, 801 the response SHOULD NOT include representation metadata other than 802 the above listed fields unless said metadata exists for the purpose 803 of guiding cache updates (e.g., future HTTP extensions). 805 If the recipient of a 304 response does not have a cached 806 representation corresponding to the entity-tag indicated by the 304 807 response, then the recipient MUST NOT use the 304 to update its own 808 cache. If this conditional request originated with an outbound 809 client, such as a user agent with its own cache sending a conditional 810 GET to a shared proxy, then the 304 response MAY be forwarded to that 811 client. Otherwise, the recipient MUST disregard the 304 response and 812 repeat the request without any preconditions. 814 If a cache uses a received 304 response to update a cache entry, the 815 cache MUST update the entry to reflect any new field values given in 816 the response. 818 4.2. 412 Precondition Failed 820 The 412 status code indicates that one or more preconditions given in 821 the request header fields evaluated to false when tested on the 822 server. This response code allows the client to place preconditions 823 on the current resource state (its current representations and 824 metadata) and thus prevent the request method from being applied if 825 the target resource is in an unexpected state. 827 5. Precedence 829 When more than one conditional request header field is present in a 830 request, the order in which the fields are evaluated becomes 831 important. In practice, the fields defined in this document are 832 consistently implemented in a single, logical order, due to the fact 833 that entity tags are presumed to be more accurate than date 834 validators. For example, the only reason to send both If-Modified- 835 Since and If-None-Match in the same GET request is to support 836 intermediary caches that might not have implemented If-None-Match, so 837 it makes sense to ignore the If-Modified-Since when entity tags are 838 understood and available for the selected representation. 840 The general rule of conditional precedence is that exact match 841 conditions are evaluated before cache-validating conditions and, 842 within that order, last-modified conditions are only evaluated if the 843 corresponding entity tag condition is not present (or not applicable 844 because the selected representation does not have an entity tag). 846 Specifically, the fields defined by this specification are evaluated 847 as follows: 849 1. When If-Match is present, evaluate it: 851 * if true, continue to step 3 853 * if false, respond 412 (Precondition Failed) 855 2. When If-Match is not present and If-Unmodified-Since is present, 856 evaluate it: 858 * if true, continue to step 3 860 * if false, respond 412 (Precondition Failed) 862 3. When the method is GET and both Range and If-Range are present, 863 evaluate it: 865 * if the validator matches, respond 206 (Partial Content) 867 * if the validator does not match, respond 200 (OK) 869 4. When If-None-Match is present, evaluate it: 871 * if true, all conditions are met 872 * if false for GET/HEAD, respond 304 (Not Modified) 874 * if false for other methods, respond 412 (Precondition Failed) 876 5. When the method is GET or HEAD, If-None-Match is not present, and 877 If-Modified-Since is present, evaluate it: 879 * if true, all conditions are met 881 * if false, respond 304 (Not Modified) 883 Any extension to HTTP/1.1 that defines additional conditional request 884 header fields ought to define its own expectations regarding the 885 order for evaluating such fields in relation to those defined in this 886 document and other conditionals that might be found in practice. 888 6. IANA Considerations 890 6.1. Status Code Registration 892 The HTTP Status Code Registry located at 893 shall be updated 894 with the registrations below: 896 +-------+---------------------+-------------+ 897 | Value | Description | Reference | 898 +-------+---------------------+-------------+ 899 | 304 | Not Modified | Section 4.1 | 900 | 412 | Precondition Failed | Section 4.2 | 901 +-------+---------------------+-------------+ 903 6.2. Header Field Registration 905 The Message Header Field Registry located at shall be 907 updated with the permanent registrations below (see [RFC3864]): 909 +---------------------+----------+----------+-------------+ 910 | Header Field Name | Protocol | Status | Reference | 911 +---------------------+----------+----------+-------------+ 912 | ETag | http | standard | Section 2.3 | 913 | If-Match | http | standard | Section 3.1 | 914 | If-Modified-Since | http | standard | Section 3.3 | 915 | If-None-Match | http | standard | Section 3.2 | 916 | If-Unmodified-Since | http | standard | Section 3.4 | 917 | Last-Modified | http | standard | Section 2.2 | 918 +---------------------+----------+----------+-------------+ 919 The change controller is: "IETF (iesg@ietf.org) - Internet 920 Engineering Task Force". 922 7. Security Considerations 924 No additional security considerations have been identified beyond 925 those applicable to HTTP in general [Part1]. 927 The validators defined by this specification are not intended to 928 ensure the validity of a representation, guard against malicious 929 changes, or detect man-in-the-middle attacks. At best, they enable 930 more efficient cache updates and optimistic concurrent writes when 931 all participants are behaving nicely. At worst, the conditions will 932 fail and the client will receive a response that is no more harmful 933 than an HTTP exchange without conditional requests. 935 8. Acknowledgments 937 See Section 9 of [Part1]. 939 9. References 941 9.1. Normative References 943 [Part1] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer 944 Protocol (HTTP/1.1): Message Syntax and Routing", 945 draft-ietf-httpbis-p1-messaging-21 (work in progress), 946 October 2012. 948 [Part2] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer 949 Protocol (HTTP/1.1): Semantics and Content", 950 draft-ietf-httpbis-p2-semantics-21 (work in progress), 951 October 2012. 953 [Part5] Fielding, R., Ed., Lafon, Y., Ed., and J. Reschke, Ed., 954 "Hypertext Transfer Protocol (HTTP/1.1): Range Requests", 955 draft-ietf-httpbis-p5-range-21 (work in progress), 956 October 2012. 958 [Part6] Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, 959 Ed., "Hypertext Transfer Protocol (HTTP/1.1): Caching", 960 draft-ietf-httpbis-p6-cache-21 (work in progress), 961 October 2012. 963 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 964 Requirement Levels", BCP 14, RFC 2119, March 1997. 966 [RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax 967 Specifications: ABNF", STD 68, RFC 5234, January 2008. 969 9.2. Informative References 971 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 972 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 973 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 975 [RFC3864] Klyne, G., Nottingham, M., and J. Mogul, "Registration 976 Procedures for Message Header Fields", BCP 90, RFC 3864, 977 September 2004. 979 [RFC4918] Dusseault, L., Ed., "HTTP Extensions for Web Distributed 980 Authoring and Versioning (WebDAV)", RFC 4918, June 2007. 982 Appendix A. Changes from RFC 2616 984 Allow weak entity-tags in all requests except range requests 985 (Sections 2.1 and 3.2). 987 Change "ETag" header field ABNF not to use quoted-string, thus 988 avoiding escaping issues. (Section 2.3) 990 Appendix B. Imported ABNF 992 The following core rules are included by reference, as defined in 993 Appendix B.1 of [RFC5234]: ALPHA (letters), CR (carriage return), 994 CRLF (CR LF), CTL (controls), DIGIT (decimal 0-9), DQUOTE (double 995 quote), HEXDIG (hexadecimal 0-9/A-F/a-f), LF (line feed), OCTET (any 996 8-bit sequence of data), SP (space), and VCHAR (any visible US-ASCII 997 character). 999 The rules below are defined in [Part1]: 1001 OWS = 1002 obs-text = 1004 The rules below are defined in other parts: 1006 HTTP-date = 1008 Appendix C. Collected ABNF 1010 ETag = entity-tag 1012 HTTP-date = 1014 If-Match = "*" / ( *( "," OWS ) entity-tag *( OWS "," [ OWS 1015 entity-tag ] ) ) 1016 If-Modified-Since = HTTP-date 1017 If-None-Match = "*" / ( *( "," OWS ) entity-tag *( OWS "," [ OWS 1018 entity-tag ] ) ) 1019 If-Unmodified-Since = HTTP-date 1021 Last-Modified = HTTP-date 1023 OWS = 1025 entity-tag = [ weak ] opaque-tag 1026 etagc = "!" / %x23-7E ; '#'-'~' 1027 / obs-text 1029 obs-text = 1030 opaque-tag = DQUOTE *etagc DQUOTE 1032 weak = %x57.2F ; W/ 1034 Appendix D. Change Log (to be removed by RFC Editor before publication) 1036 Changes up to the first Working Group Last Call draft are summarized 1037 in . 1040 D.1. Since draft-ietf-httpbis-p4-conditional-19 1042 Closed issues: 1044 o : "Need to 1045 clarify eval order/interaction of conditional headers" 1047 o : "Required 1048 headers on 304 and 206" 1050 o : "Optionality 1051 of Conditional Request Support" 1053 o : "ETags and 1054 Conditional Requests" 1056 o : "ABNF 1057 requirements for recipients" 1059 o : "Rare cases" 1061 o : "Conditional 1062 Request Security Considerations" 1064 o : "If-Modified- 1065 Since lacks definition for method != GET" 1067 o : "refactor 1068 conditional header field descriptions" 1070 D.2. Since draft-ietf-httpbis-p4-conditional-20 1072 o Conformance criteria and considerations regarding error handling 1073 are now defined in Part 1. 1075 Index 1077 3 1078 304 Not Modified (status code) 18 1080 4 1081 412 Precondition Failed (status code) 18 1083 E 1084 ETag header field 9 1086 G 1087 Grammar 1088 entity-tag 9 1089 ETag 9 1090 etagc 9 1091 If-Match 14 1092 If-Modified-Since 16 1093 If-None-Match 15 1094 If-Unmodified-Since 17 1095 Last-Modified 7 1096 opaque-tag 9 1097 weak 9 1099 I 1100 If-Match header field 13 1101 If-Modified-Since header field 16 1102 If-None-Match header field 14 1103 If-Unmodified-Since header field 17 1105 L 1106 Last-Modified header field 7 1108 M 1109 metadata 5 1111 S 1112 selected representation 4 1114 V 1115 validator 5 1116 strong 5 1117 weak 5 1119 Authors' Addresses 1121 Roy T. Fielding (editor) 1122 Adobe Systems Incorporated 1123 345 Park Ave 1124 San Jose, CA 95110 1125 USA 1127 EMail: fielding@gbiv.com 1128 URI: http://roy.gbiv.com/ 1130 Julian F. Reschke (editor) 1131 greenbytes GmbH 1132 Hafenweg 16 1133 Muenster, NW 48155 1134 Germany 1136 EMail: julian.reschke@greenbytes.de 1137 URI: http://greenbytes.de/tech/webdav/