idnits 2.17.1 draft-ietf-httpbis-p4-conditional-26.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 (February 6, 2014) is 3694 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) -- 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 (~~), 1 warning (==), 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: August 10, 2014 February 6, 2014 8 Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests 9 draft-ietf-httpbis-p4-conditional-26 11 Abstract 13 The Hypertext Transfer Protocol (HTTP) is a stateless application- 14 level 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 August 10, 2014. 50 Copyright Notice 52 Copyright (c) 2014 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 . . . . . . . . . . . . . . . . . . . . . 4 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. When to Use Entity-tags and Last-Modified Dates . . . . . 12 93 3. Precondition Header Fields . . . . . . . . . . . . . . . . . . 13 94 3.1. If-Match . . . . . . . . . . . . . . . . . . . . . . . . . 13 95 3.2. If-None-Match . . . . . . . . . . . . . . . . . . . . . . 14 96 3.3. If-Modified-Since . . . . . . . . . . . . . . . . . . . . 15 97 3.4. If-Unmodified-Since . . . . . . . . . . . . . . . . . . . 16 98 3.5. If-Range . . . . . . . . . . . . . . . . . . . . . . . . . 18 99 4. Status Code Definitions . . . . . . . . . . . . . . . . . . . 18 100 4.1. 304 Not Modified . . . . . . . . . . . . . . . . . . . . . 18 101 4.2. 412 Precondition Failed . . . . . . . . . . . . . . . . . 18 102 5. Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . 19 103 6. Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . 19 104 7. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 21 105 7.1. Status Code Registration . . . . . . . . . . . . . . . . . 21 106 7.2. Header Field Registration . . . . . . . . . . . . . . . . 21 107 8. Security Considerations . . . . . . . . . . . . . . . . . . . 22 108 9. Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . 22 109 10. References . . . . . . . . . . . . . . . . . . . . . . . . . . 23 110 10.1. Normative References . . . . . . . . . . . . . . . . . . . 23 111 10.2. Informative References . . . . . . . . . . . . . . . . . . 23 112 Appendix A. Changes from RFC 2616 . . . . . . . . . . . . . . . . 23 113 Appendix B. Imported ABNF . . . . . . . . . . . . . . . . . . . . 24 114 Appendix C. Collected ABNF . . . . . . . . . . . . . . . . . . . 24 115 Appendix D. Change Log (to be removed by RFC Editor before 116 publication) . . . . . . . . . . . . . . . . . . . . 25 117 D.1. Since draft-ietf-httpbis-p4-conditional-24 . . . . . . . . 25 118 D.2. Since draft-ietf-httpbis-p4-conditional-25 . . . . . . . . 25 119 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 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. This document 126 defines the HTTP/1.1 conditional request mechanisms in terms of the 127 architecture, syntax notation, and conformance criteria defined in 128 [Part1]. 130 Conditional GET requests are the most efficient mechanism for HTTP 131 cache updates [Part6]. Conditionals can also be applied to state- 132 changing methods, such as PUT and DELETE, to prevent the "lost 133 update" problem: one client accidentally overwriting the work of 134 another client that has been acting in parallel. 136 Conditional request preconditions are based on the state of the 137 target resource as a whole (its current value set) or the state as 138 observed in a previously obtained representation (one value in that 139 set). A resource might have multiple current representations, each 140 with its own observable state. The conditional request mechanisms 141 assume that the mapping of requests to a "selected representation" 142 (Section 3 of [Part2]) will be consistent over time if the server 143 intends to take advantage of conditionals. Regardless, if the 144 mapping is inconsistent and the server is unable to select the 145 appropriate representation, then no harm will result when the 146 precondition evaluates to false. 148 The conditional request preconditions defined by this specification 149 (Section 3) are evaluated when applicable to the recipient 150 (Section 5) according to their order of precedence (Section 6). 152 1.1. Conformance and Error Handling 154 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 155 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 156 document are to be interpreted as described in [RFC2119]. 158 Conformance criteria and considerations regarding error handling are 159 defined in Section 2.5 of [Part1]. 161 1.2. Syntax Notation 163 This specification uses the Augmented Backus-Naur Form (ABNF) 164 notation of [RFC5234] with a list extension, defined in Section 7 of 165 [Part1], that allows for compact definition of comma-separated lists 166 using a '#' operator (similar to how the '*' operator indicates 167 repetition). Appendix B describes rules imported from other 168 documents. Appendix C shows the collected grammar with all list 169 operators expanded to standard ABNF notation. 171 2. Validators 173 This specification defines two forms of metadata that are commonly 174 used to observe resource state and test for preconditions: 175 modification dates (Section 2.2) and opaque entity tags 176 (Section 2.3). Additional metadata that reflects resource state has 177 been defined by various extensions of HTTP, such as WebDAV [RFC4918], 178 that are beyond the scope of this specification. A resource metadata 179 value is referred to as a "validator" when it is used within a 180 precondition. 182 2.1. Weak versus Strong 184 Validators come in two flavors: strong or weak. Weak validators are 185 easy to generate but are far less useful for comparisons. Strong 186 validators are ideal for comparisons but can be very difficult (and 187 occasionally impossible) to generate efficiently. Rather than impose 188 that all forms of resource adhere to the same strength of validator, 189 HTTP exposes the type of validator in use and imposes restrictions on 190 when weak validators can be used as preconditions. 192 A "strong validator" is representation metadata that changes value 193 whenever a change occurs to the representation data that would be 194 observable in the payload body of a 200 (OK) response to GET. 196 A strong validator might change for reasons other than a change to 197 the representation data, such as when a semantically significant part 198 of the representation metadata is changed (e.g., Content-Type), but 199 it is in the best interests of the origin server to only change the 200 value when it is necessary to invalidate the stored responses held by 201 remote caches and authoring tools. 203 Cache entries might persist for arbitrarily long periods, regardless 204 of expiration times. Thus, a cache might attempt to validate an 205 entry using a validator that it obtained in the distant past. A 206 strong validator is unique across all versions of all representations 207 associated with a particular resource over time. However, there is 208 no implication of uniqueness across representations of different 209 resources (i.e., the same strong validator might be in use for 210 representations of multiple resources at the same time and does not 211 imply that those representations are equivalent). 213 There are a variety of strong validators used in practice. The best 214 are based on strict revision control, wherein each change to a 215 representation always results in a unique node name and revision 216 identifier being assigned before the representation is made 217 accessible to GET. A collision-resistant hash function applied to 218 the representation data is also sufficient if the data is available 219 prior to the response header fields being sent and the digest does 220 not need to be recalculated every time a validation request is 221 received. However, if a resource has distinct representations that 222 differ only in their metadata, such as might occur with content 223 negotiation over media types that happen to share the same data 224 format, then the origin server needs to incorporate additional 225 information in the validator to distinguish those representations. 227 In contrast, a "weak validator" is representation metadata that might 228 not change for every change to the representation data. This 229 weakness might be due to limitations in how the value is calculated, 230 such as clock resolution or an inability to ensure uniqueness for all 231 possible representations of the resource, or due to a desire by the 232 resource owner to group representations by some self-determined set 233 of equivalency rather than unique sequences of data. An origin 234 server SHOULD change a weak entity-tag whenever it considers prior 235 representations to be unacceptable as a substitute for the current 236 representation. In other words, a weak entity-tag ought to change 237 whenever the origin server wants caches to invalidate old responses. 239 For example, the representation of a weather report that changes in 240 content every second, based on dynamic measurements, might be grouped 241 into sets of equivalent representations (from the origin server's 242 perspective) with the same weak validator in order to allow cached 243 representations to be valid for a reasonable period of time (perhaps 244 adjusted dynamically based on server load or weather quality). 245 Likewise, a representation's modification time, if defined with only 246 one-second resolution, might be a weak validator if it is possible 247 for the representation to be modified twice during a single second 248 and retrieved between those modifications. 250 Likewise, a validator is weak if it is shared by two or more 251 representations of a given resource at the same time, unless those 252 representations have identical representation data. For example, if 253 the origin server sends the same validator for a representation with 254 a gzip content coding applied as it does for a representation with no 255 content coding, then that validator is weak. However, two 256 simultaneous representations might share the same strong validator if 257 they differ only in the representation metadata, such as when two 258 different media types are available for the same representation data. 260 Strong validators are usable for all conditional requests, including 261 cache validation, partial content ranges, and "lost update" 262 avoidance. Weak validators are only usable when the client does not 263 require exact equality with previously obtained representation data, 264 such as when validating a cache entry or limiting a web traversal to 265 recent changes. 267 2.2. Last-Modified 269 The "Last-Modified" header field in a response provides a timestamp 270 indicating the date and time at which the origin server believes the 271 selected representation was last modified, as determined at the 272 conclusion of handling the request. 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 An origin server 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 in a response provides the current entity-tag 366 for the selected representation, as determined at the conclusion of 367 handling the request. An entity-tag is an opaque validator for 368 differentiating between multiple representations of the same 369 resource, regardless of whether those multiple representations are 370 due to resource state changes over time, content negotiation 371 resulting in multiple representations being valid at the same time, 372 or both. An entity-tag consists of an opaque quoted string, possibly 373 prefixed by a weakness indicator. 375 ETag = entity-tag 377 entity-tag = [ weak ] opaque-tag 378 weak = %x57.2F ; "W/", case-sensitive 379 opaque-tag = DQUOTE *etagc DQUOTE 380 etagc = %x21 / %x23-7E / obs-text 381 ; VCHAR except double quotes, plus obs-text 383 Note: Previously, opaque-tag was defined to be a quoted-string 384 ([RFC2616], Section 3.11), thus some recipients might perform 385 backslash unescaping. Servers therefore ought to avoid backslash 386 characters in entity tags. 388 An entity-tag can be more reliable for validation than a modification 389 date in situations where it is inconvenient to store modification 390 dates, where the one-second resolution of HTTP date values is not 391 sufficient, or where modification dates are not consistently 392 maintained. 394 Examples: 396 ETag: "xyzzy" 397 ETag: W/"xyzzy" 398 ETag: "" 400 An entity-tag can be either a weak or strong validator, with strong 401 being the default. If an origin server provides an entity-tag for a 402 representation and the generation of that entity-tag does not satisfy 403 all of the characteristics of a strong validator (Section 2.1), then 404 the origin server MUST mark the entity-tag as weak by prefixing its 405 opaque value with "W/" (case-sensitive). 407 2.3.1. Generation 409 The principle behind entity-tags is that only the service author 410 knows the implementation of a resource well enough to select the most 411 accurate and efficient validation mechanism for that resource, and 412 that any such mechanism can be mapped to a simple sequence of octets 413 for easy comparison. Since the value is opaque, there is no need for 414 the client to be aware of how each entity-tag is constructed. 416 For example, a resource that has implementation-specific versioning 417 applied to all changes might use an internal revision number, perhaps 418 combined with a variance identifier for content negotiation, to 419 accurately differentiate between representations. Other 420 implementations might use a collision-resistant hash of 421 representation content, a combination of various file attributes, or 422 a modification timestamp that has sub-second resolution. 424 An origin server 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 Strong comparison: two entity-tags are equivalent if both are not 437 weak and their opaque-tags match character-by-character. 439 o Weak comparison: two entity-tags are equivalent if their opaque- 440 tags match character-by-character, regardless of either or both 441 being tagged as "weak". 443 The example below shows the results for a set of entity-tag pairs, 444 and both the weak and strong comparison function results: 446 +--------+--------+-------------------+-----------------+ 447 | ETag 1 | ETag 2 | Strong Comparison | Weak Comparison | 448 +--------+--------+-------------------+-----------------+ 449 | W/"1" | W/"1" | no match | match | 450 | W/"1" | W/"2" | no match | no match | 451 | W/"1" | "1" | no match | match | 452 | "1" | "1" | match | match | 453 +--------+--------+-------------------+-----------------+ 455 2.3.3. Example: Entity-tags Varying on Content-Negotiated Resources 457 Consider a resource that is subject to content negotiation (Section 458 3.4 of [Part2]), and where the representations sent in response to a 459 GET request vary based on the Accept-Encoding request header field 460 (Section 5.3.4 of [Part2]): 462 >> Request: 464 GET /index HTTP/1.1 465 Host: www.example.com 466 Accept-Encoding: gzip 468 In this case, the response might or might not use the gzip content 469 coding. If it does not, the response might look like: 471 >> Response: 473 HTTP/1.1 200 OK 474 Date: Fri, 26 Mar 2010 00:05:00 GMT 475 ETag: "123-a" 476 Content-Length: 70 477 Vary: Accept-Encoding 478 Content-Type: text/plain 480 Hello World! 481 Hello World! 482 Hello World! 483 Hello World! 484 Hello World! 486 An alternative representation that does use gzip content coding would 487 be: 489 >> Response: 491 HTTP/1.1 200 OK 492 Date: Fri, 26 Mar 2010 00:05:00 GMT 493 ETag: "123-b" 494 Content-Length: 43 495 Vary: Accept-Encoding 496 Content-Type: text/plain 497 Content-Encoding: gzip 499 ...binary data... 501 Note: Content codings are a property of the representation data, 502 so a strong entity-tag for a content-encoded representation has to 503 be distinct from the entity tag of an unencoded representation to 504 prevent potential conflicts during cache updates and range 505 requests. In contrast, transfer codings (Section 4 of [Part1]) 506 apply only during message transfer and do not result in distinct 507 entity-tags. 509 2.4. When to Use Entity-tags and Last-Modified Dates 511 In 200 (OK) responses to GET or HEAD, an origin server: 513 o SHOULD send an entity-tag validator unless it is not feasible to 514 generate one. 516 o MAY send a weak entity-tag instead of a strong entity-tag, if 517 performance considerations support the use of weak entity-tags, or 518 if it is unfeasible to send a strong entity-tag. 520 o SHOULD send a Last-Modified value if it is feasible to send one. 522 In other words, the preferred behavior for an origin server is to 523 send both a strong entity-tag and a Last-Modified value in successful 524 responses to a retrieval request. 526 A client: 528 o MUST send that entity-tag in any cache validation request (using 529 If-Match or If-None-Match) if an entity-tag has been provided by 530 the origin server. 532 o SHOULD send the Last-Modified value in non-subrange cache 533 validation requests (using If-Modified-Since) if only a Last- 534 Modified value has been provided by the origin server. 536 o MAY send the Last-Modified value in subrange cache validation 537 requests (using If-Unmodified-Since) if only a Last-Modified value 538 has been provided by an HTTP/1.0 origin server. The user agent 539 SHOULD provide a way to disable this, in case of difficulty. 541 o SHOULD send both validators in cache validation requests if both 542 an entity-tag and a Last-Modified value have been provided by the 543 origin server. This allows both HTTP/1.0 and HTTP/1.1 caches to 544 respond appropriately. 546 3. Precondition Header Fields 548 This section defines the syntax and semantics of HTTP/1.1 header 549 fields for applying preconditions on requests. Section 5 defines 550 when the preconditions are applied. Section 6 defines the order of 551 evaluation when more than one precondition is present. 553 3.1. If-Match 555 The "If-Match" header field makes the request method conditional on 556 the recipient origin server either having at least one current 557 representation of the target resource, when the field-value is "*", 558 or having a current representation of the target resource that has an 559 entity-tag matching a member of the list of entity-tags provided in 560 the field-value. 562 An origin server MUST use the strong comparison function when 563 comparing entity-tags for If-Match (Section 2.3.2), since the client 564 intends this precondition to prevent the method from being applied if 565 there have been any changes to the representation data. 567 If-Match = "*" / 1#entity-tag 569 Examples: 571 If-Match: "xyzzy" 572 If-Match: "xyzzy", "r2d2xxxx", "c3piozzzz" 573 If-Match: * 575 If-Match is most often used with state-changing methods (e.g., POST, 576 PUT, DELETE) to prevent accidental overwrites when multiple user 577 agents might be acting in parallel on the same resource (i.e., to 578 prevent the "lost update" problem). It can also be used with safe 579 methods to abort a request if the selected representation does not 580 match one already stored (or partially stored) from a prior request. 582 An origin server that receives an If-Match header field MUST evaluate 583 the condition prior to performing the method (Section 5). If the 584 field-value is "*", the condition is false if the origin server does 585 not have a current representation for the target resource. If the 586 field-value is a list of entity-tags, the condition is false if none 587 of the listed tags match the entity-tag of the selected 588 representation. 590 An origin server MUST NOT perform the requested method if a received 591 If-Match condition evaluates to false; instead the origin server MUST 592 respond with either: a) the 412 (Precondition Failed) status code; 593 or, b) one of the 2xx (Successful) status codes if the origin server 594 has verified that a state change is being requested and the final 595 state is already reflected in the current state of the target 596 resource (i.e., the change requested by the user agent has already 597 succeeded, but the user agent might not be aware of it, perhaps 598 because the prior response was lost or a compatible change was made 599 by some other user agent). In the latter case, the origin server 600 MUST NOT send a validator header field in the response unless it can 601 verify that the request is a duplicate of an immediately prior change 602 made by the same user agent. 604 The If-Match header field can be ignored by caches and intermediaries 605 because it is not applicable to a stored response. 607 3.2. If-None-Match 609 The "If-None-Match" header field makes the request method conditional 610 on a recipient cache or origin server either not having any current 611 representation of the target resource, when the field-value is "*", 612 or having a selected representation with an entity-tag that does not 613 match any of those listed in the field-value. 615 A recipient MUST use the weak comparison function when comparing 616 entity-tags for If-None-Match (Section 2.3.2), since weak entity-tags 617 can be used for cache validation even if there have been changes to 618 the representation data. 620 If-None-Match = "*" / 1#entity-tag 622 Examples: 624 If-None-Match: "xyzzy" 625 If-None-Match: W/"xyzzy" 626 If-None-Match: "xyzzy", "r2d2xxxx", "c3piozzzz" 627 If-None-Match: W/"xyzzy", W/"r2d2xxxx", W/"c3piozzzz" 628 If-None-Match: * 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. When a client desires to update one or more 633 stored responses that have entity-tags, the client SHOULD generate an 634 If-None-Match header field containing a list of those entity-tags 635 when making a GET request; this allows recipient servers to send a 636 304 (Not Modified) response to indicate when one of those stored 637 responses matches the selected representation. 639 If-None-Match can also be used with a value of "*" to prevent an 640 unsafe request method (e.g., PUT) from inadvertently modifying an 641 existing representation of the target resource when the client 642 believes that the resource does not have a current representation 643 (Section 4.2.1 of [Part2]). This is a variation on the "lost update" 644 problem that might arise if more than one client attempts to create 645 an initial representation for the target resource. 647 An origin server that receives an If-None-Match header field MUST 648 evaluate the condition prior to performing the method (Section 5). 649 If the field-value is "*", the condition is false if the origin 650 server has a current representation for the target resource. If the 651 field-value is a list of entity-tags, the condition is false if one 652 of the listed tags match the entity-tag of the selected 653 representation. 655 An origin server MUST NOT perform the requested method if the 656 condition evaluates to false; instead, the origin server MUST respond 657 with either a) the 304 (Not Modified) status code if the request 658 method is GET or HEAD; or, b) the 412 (Precondition Failed) status 659 code for all other request methods. 661 Requirements on cache handling of a received If-None-Match header 662 field are defined in Section 4.3.2 of [Part6]. 664 3.3. If-Modified-Since 666 The "If-Modified-Since" header field makes a GET or HEAD request 667 method conditional on the selected representation's modification date 668 being more recent than the date provided in the field-value. 669 Transfer of the selected representation's data is avoided if that 670 data has not changed. 672 If-Modified-Since = HTTP-date 674 An example of the field is: 676 If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT 678 A recipient MUST ignore If-Modified-Since if the request contains an 679 If-None-Match header field; the condition in If-None-Match is 680 considered to be a more accurate replacement for the condition in If- 681 Modified-Since and the two are only combined for the sake of 682 interoperating with older intermediaries that might not implement If- 683 None-Match. 685 A recipient MUST ignore the If-Modified-Since header field if the 686 received field-value is not a valid HTTP-date, or if the request 687 method is neither GET nor HEAD. 689 A recipient MUST interpret an If-Modified-Since field-value's 690 timestamp in terms of the origin server's clock. 692 If-Modified-Since is typically used for two distinct purposes: 1) to 693 allow efficient updates of a cached representation that does not have 694 an entity-tag; and, 2) to limit the scope of a web traversal to 695 resources that have recently changed. 697 When used for cache updates, a cache will typically use the value of 698 the cached message's Last-Modified field to generate the field value 699 of If-Modified-Since. This behavior is most interoperable for cases 700 where clocks are poorly synchronized or when the server has chosen to 701 only honor exact timestamp matches (due to a problem with Last- 702 Modified dates that appear to go "back in time" when the origin 703 server's clock is corrected or a representation is restored from an 704 archived backup). However, caches occasionally generate the field 705 value based on other data, such as the Date header field of the 706 cached message or the local clock time that the message was received, 707 particularly when the cached message does not contain a Last-Modified 708 field. 710 When used for limiting the scope of retrieval to a recent time 711 window, a user agent will generate an If-Modified-Since field value 712 based on either its own local clock or a Date header field received 713 from the server in a prior response. Origin servers that choose an 714 exact timestamp match based on the selected representation's Last- 715 Modified field will not be able to help the user agent limit its data 716 transfers to only those changed during the specified window. 718 An origin server that receives an If-Modified-Since header field 719 SHOULD evaluate the condition prior to performing the method 720 (Section 5). The origin server SHOULD NOT perform the requested 721 method if the selected representation's last modification date is 722 earlier than or equal to the date provided in the field-value; 723 instead, the origin server SHOULD generate a 304 (Not Modified) 724 response, including only those metadata that are useful for 725 identifying or updating a previously cached response. 727 Requirements on cache handling of a received If-Modified-Since header 728 field are defined in Section 4.3.2 of [Part6]. 730 3.4. If-Unmodified-Since 732 The "If-Unmodified-Since" header field makes the request method 733 conditional on the selected representation's last modification date 734 being earlier than or equal to the date provided in the field-value. 735 This field accomplishes the same purpose as If-Match for cases where 736 the user agent does not have an entity-tag for the representation. 738 If-Unmodified-Since = HTTP-date 740 An example of the field is: 742 If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT 744 A recipient MUST ignore If-Unmodified-Since if the request contains 745 an If-Match header field; the condition in If-Match is considered to 746 be a more accurate replacement for the condition in If-Unmodified- 747 Since and the two are only combined for the sake of interoperating 748 with older intermediaries that might not implement If-Match. 750 A recipient MUST ignore the If-Unmodified-Since header field if the 751 received field-value is not a valid HTTP-date. 753 A recipient MUST interpret an If-Unmodified-Since field-value's 754 timestamp in terms of the origin server's clock. 756 If-Unmodified-Since is most often used with state-changing methods 757 (e.g., POST, PUT, DELETE) to prevent accidental overwrites when 758 multiple user agents might be acting in parallel on a resource that 759 does not supply entity-tags with its representations (i.e., to 760 prevent the "lost update" problem). It can also be used with safe 761 methods to abort a request if the selected representation does not 762 match one already stored (or partially stored) from a prior request. 764 An origin server that receives an If-Unmodified-Since header field 765 MUST evaluate the condition prior to performing the method 766 (Section 5). The origin server MUST NOT perform the requested method 767 if the selected representation's last modification date is more 768 recent than the date provided in the field-value; instead the origin 769 server MUST respond with either: a) the 412 (Precondition Failed) 770 status code; or, b) one of the 2xx (Successful) status codes if the 771 origin server has verified that a state change is being requested and 772 the final state is already reflected in the current state of the 773 target resource (i.e., the change requested by the user agent has 774 already succeeded, but the user agent might not be aware of that 775 because the prior response message was lost or a compatible change 776 was made by some other user agent). In the latter case, the origin 777 server MUST NOT send a validator header field in the response unless 778 it can verify that the request is a duplicate of an immediately prior 779 change made by the same user agent. 781 The If-Unmodified-Since header field can be ignored by caches and 782 intermediaries because it is not applicable to a stored response. 784 3.5. If-Range 786 The "If-Range" header field provides a special conditional request 787 mechanism that is similar to the If-Match and If-Unmodified-Since 788 header fields but instructs the recipient to ignore the Range header 789 field if the validator doesn't match, resulting in transfer of the 790 new selected representation instead of a 412 response. If-Range is 791 defined in Section 3.2 of [Part5]. 793 4. Status Code Definitions 795 4.1. 304 Not Modified 797 The 304 (Not Modified) status code indicates that a conditional GET 798 or HEAD request has been received and would have resulted in a 200 799 (OK) response if it were not for the fact that the condition has 800 evaluated to false. In other words, there is no need for the server 801 to transfer a representation of the target resource because the 802 request indicates that the client, which made the request 803 conditional, already has a valid representation; the server is 804 therefore redirecting the client to make use of that stored 805 representation as if it were the payload of a 200 (OK) response. 807 The server generating a 304 response MUST generate any of the 808 following header fields that would have been sent in a 200 (OK) 809 response to the same request: Cache-Control, Content-Location, Date, 810 ETag, Expires, and Vary. 812 Since the goal of a 304 response is to minimize information transfer 813 when the recipient already has one or more cached representations, a 814 sender SHOULD NOT generate representation metadata other than the 815 above listed fields unless said metadata exists for the purpose of 816 guiding cache updates (e.g., Last-Modified might be useful if the 817 response does not have an ETag field). 819 Requirements on a cache that receives a 304 response are defined in 820 Section 4.3.4 of [Part6]. If the conditional request originated with 821 an outbound client, such as a user agent with its own cache sending a 822 conditional GET to a shared proxy, then the proxy SHOULD forward the 823 304 response to that client. 825 A 304 response cannot contain a message-body; it is always terminated 826 by the first empty line after the header fields. 828 4.2. 412 Precondition Failed 830 The 412 (Precondition Failed) status code indicates that one or more 831 conditions given in the request header fields evaluated to false when 832 tested on the server. This response code allows the client to place 833 preconditions on the current resource state (its current 834 representations and metadata) and thus prevent the request method 835 from being applied if the target resource is in an unexpected state. 837 5. Evaluation 839 Except when excluded below, a recipient cache or origin server MUST 840 evaluate received request preconditions after it has successfully 841 performed its normal request checks and just before it would perform 842 the action associated with the request method. A server MUST ignore 843 all received preconditions if its response to the same request 844 without those conditions would have been a status code other than a 845 2xx or 412 (Precondition Failed). In other words, redirects and 846 failures take precedence over the evaluation of preconditions in 847 conditional requests. 849 A server that is not the origin server for the target resource and 850 cannot act as a cache for requests on the target resource MUST NOT 851 evaluate the conditional request header fields defined by this 852 specification, and MUST forward them if the request is forwarded, 853 since the generating client intends that they be evaluated by a 854 server that can provide a current representation. Likewise, a server 855 MUST ignore the conditional request header fields defined by this 856 specification when received with a request method that does not 857 involve the selection or modification of a selected representation, 858 such as CONNECT, OPTIONS, or TRACE. 860 Conditional request header fields that are defined by extensions to 861 HTTP might place conditions on all recipients, on the state of the 862 target resource in general, or on a group of resources. For 863 instance, the "If" header field in WebDAV can make a request 864 conditional on various aspects of multiple resources, such as locks, 865 if the recipient understands and implements that field ([RFC4918], 866 Section 10.4). 868 Although conditional request header fields are defined as being 869 usable with the HEAD method (to keep HEAD's semantics consistent with 870 those of GET), there is no point in sending a conditional HEAD 871 because a successful response is around the same size as a 304 (Not 872 Modified) response and more useful than a 412 (Precondition Failed) 873 response. 875 6. Precedence 877 When more than one conditional request header field is present in a 878 request, the order in which the fields are evaluated becomes 879 important. In practice, the fields defined in this document are 880 consistently implemented in a single, logical order, since "lost 881 update" preconditions have more strict requirements than cache 882 validation, a validated cache is more efficient than a partial 883 response, and entity tags are presumed to be more accurate than date 884 validators. 886 A recipient cache or origin server MUST evaluate the request 887 preconditions defined by this specification in the following order: 889 1. When recipient is the origin server and If-Match is present, 890 evaluate the If-Match precondition: 892 * if true, continue to step 3 894 * if false, respond 412 (Precondition Failed) unless it can be 895 determined that the state-changing request has already 896 succeeded (see Section 3.1) 898 2. When recipient is the origin server, If-Match is not present, and 899 If-Unmodified-Since is present, evaluate the If-Unmodified-Since 900 precondition: 902 * if true, continue to step 3 904 * if false, respond 412 (Precondition Failed) unless it can be 905 determined that the state-changing request has already 906 succeeded (see Section 3.4) 908 3. When If-None-Match is present, evaluate the If-None-Match 909 precondition: 911 * if true, continue to step 5 913 * if false for GET/HEAD, respond 304 (Not Modified) 915 * if false for other methods, respond 412 (Precondition Failed) 917 4. When the method is GET or HEAD, If-None-Match is not present, and 918 If-Modified-Since is present, evaluate the If-Modified-Since 919 precondition: 921 * if true, continue to step 5 923 * if false, respond 304 (Not Modified) 925 5. When the method is GET and both Range and If-Range are present, 926 evaluate the If-Range precondition: 928 * if the validator matches and the Range specification is 929 applicable to the selected representation, respond 206 930 (Partial Content) [Part5] 932 6. Otherwise, 934 * all conditions are met, so perform the requested action and 935 respond according to its success or failure. 937 Any extension to HTTP/1.1 that defines additional conditional request 938 header fields ought to define its own expectations regarding the 939 order for evaluating such fields in relation to those defined in this 940 document and other conditionals that might be found in practice. 942 7. IANA Considerations 944 7.1. Status Code Registration 946 The HTTP Status Code Registry located at 947 shall be updated 948 with the registrations below: 950 +-------+---------------------+-------------+ 951 | Value | Description | Reference | 952 +-------+---------------------+-------------+ 953 | 304 | Not Modified | Section 4.1 | 954 | 412 | Precondition Failed | Section 4.2 | 955 +-------+---------------------+-------------+ 957 7.2. Header Field Registration 959 HTTP header fields are registered within the Message Header Field 960 Registry maintained at . 963 This document defines the following HTTP header fields, so their 964 associated registry entries shall be updated according to the 965 permanent registrations below (see [BCP90]): 967 +---------------------+----------+----------+-------------+ 968 | Header Field Name | Protocol | Status | Reference | 969 +---------------------+----------+----------+-------------+ 970 | ETag | http | standard | Section 2.3 | 971 | If-Match | http | standard | Section 3.1 | 972 | If-Modified-Since | http | standard | Section 3.3 | 973 | If-None-Match | http | standard | Section 3.2 | 974 | If-Unmodified-Since | http | standard | Section 3.4 | 975 | Last-Modified | http | standard | Section 2.2 | 976 +---------------------+----------+----------+-------------+ 978 The change controller is: "IETF (iesg@ietf.org) - Internet 979 Engineering Task Force". 981 8. Security Considerations 983 This section is meant to inform developers, information providers, 984 and users of known security concerns specific to the HTTP conditional 985 request mechanisms. More general security considerations are 986 addressed in HTTP messaging [Part1] and semantics [Part2]. 988 The validators defined by this specification are not intended to 989 ensure the validity of a representation, guard against malicious 990 changes, or detect man-in-the-middle attacks. At best, they enable 991 more efficient cache updates and optimistic concurrent writes when 992 all participants are behaving nicely. At worst, the conditions will 993 fail and the client will receive a response that is no more harmful 994 than an HTTP exchange without conditional requests. 996 An entity-tag can be abused in ways that create privacy risks. For 997 example, a site might deliberately construct a semantically invalid 998 entity-tag that is unique to the user or user agent, send it in a 999 cacheable response with a long freshness time, and then read that 1000 entity-tag in later conditional requests as a means of re-identifying 1001 that user or user agent. Such an identifying tag would become a 1002 persistent identifier for as long as the user agent retained the 1003 original cache entry. User agents that cache representations ought 1004 to ensure that the cache is cleared or replaced whenever the user 1005 performs privacy-maintaining actions, such as clearing stored cookies 1006 or changing to a private browsing mode. 1008 9. Acknowledgments 1010 See Section 10 of [Part1]. 1012 10. References 1013 10.1. Normative References 1015 [Part1] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer 1016 Protocol (HTTP/1.1): Message Syntax and Routing", 1017 draft-ietf-httpbis-p1-messaging-26 (work in progress), 1018 February 2014. 1020 [Part2] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer 1021 Protocol (HTTP/1.1): Semantics and Content", 1022 draft-ietf-httpbis-p2-semantics-26 (work in progress), 1023 February 2014. 1025 [Part5] Fielding, R., Ed., Lafon, Y., Ed., and J. Reschke, Ed., 1026 "Hypertext Transfer Protocol (HTTP/1.1): Range Requests", 1027 draft-ietf-httpbis-p5-range-26 (work in progress), 1028 February 2014. 1030 [Part6] Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, 1031 Ed., "Hypertext Transfer Protocol (HTTP/1.1): Caching", 1032 draft-ietf-httpbis-p6-cache-26 (work in progress), 1033 February 2014. 1035 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1036 Requirement Levels", BCP 14, RFC 2119, March 1997. 1038 [RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax 1039 Specifications: ABNF", STD 68, RFC 5234, January 2008. 1041 10.2. Informative References 1043 [BCP90] Klyne, G., Nottingham, M., and J. Mogul, "Registration 1044 Procedures for Message Header Fields", BCP 90, RFC 3864, 1045 September 2004. 1047 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 1048 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 1049 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 1051 [RFC4918] Dusseault, L., Ed., "HTTP Extensions for Web Distributed 1052 Authoring and Versioning (WebDAV)", RFC 4918, June 2007. 1054 Appendix A. Changes from RFC 2616 1056 The definition of validator weakness has been expanded and clarified. 1057 (Section 2.1) 1059 Weak entity-tags are now allowed in all requests except range 1060 requests. (Sections 2.1 and 3.2) 1061 The ETag header field ABNF has been changed to not use quoted-string, 1062 thus avoiding escaping issues. (Section 2.3) 1064 ETag is defined to provide an entity tag for the selected 1065 representation, thereby clarifying what it applies to in various 1066 situations (such as a PUT response). (Section 2.3) 1068 The precedence for evaluation of conditional requests has been 1069 defined. (Section 6) 1071 Appendix B. Imported ABNF 1073 The following core rules are included by reference, as defined in 1074 Appendix B.1 of [RFC5234]: ALPHA (letters), CR (carriage return), 1075 CRLF (CR LF), CTL (controls), DIGIT (decimal 0-9), DQUOTE (double 1076 quote), HEXDIG (hexadecimal 0-9/A-F/a-f), LF (line feed), OCTET (any 1077 8-bit sequence of data), SP (space), and VCHAR (any visible US-ASCII 1078 character). 1080 The rules below are defined in [Part1]: 1082 OWS = 1083 obs-text = 1085 The rules below are defined in other parts: 1087 HTTP-date = 1089 Appendix C. Collected ABNF 1091 In the collected ABNF below, list rules are expanded as per Section 1092 1.2 of [Part1]. 1094 ETag = entity-tag 1096 HTTP-date = 1098 If-Match = "*" / ( *( "," OWS ) entity-tag *( OWS "," [ OWS 1099 entity-tag ] ) ) 1100 If-Modified-Since = HTTP-date 1101 If-None-Match = "*" / ( *( "," OWS ) entity-tag *( OWS "," [ OWS 1102 entity-tag ] ) ) 1103 If-Unmodified-Since = HTTP-date 1105 Last-Modified = HTTP-date 1107 OWS = 1109 entity-tag = [ weak ] opaque-tag 1110 etagc = "!" / %x23-7E ; '#'-'~' 1111 / obs-text 1113 obs-text = 1114 opaque-tag = DQUOTE *etagc DQUOTE 1116 weak = %x57.2F ; W/ 1118 Appendix D. Change Log (to be removed by RFC Editor before publication) 1120 Changes up to the IETF Last Call draft are summarized in . 1123 D.1. Since draft-ietf-httpbis-p4-conditional-24 1125 Closed issues: 1127 o : "APPSDIR 1128 review of draft-ietf-httpbis-p4-conditional-24" 1130 D.2. Since draft-ietf-httpbis-p4-conditional-25 1132 Closed issues: 1134 o : "add 1135 'stateless' to Abstract" 1137 o : "improve 1138 introduction of list rule" 1140 o : "augment 1141 security considerations with pointers to current research" 1143 Index 1145 3 1146 304 Not Modified (status code) 18 1148 4 1149 412 Precondition Failed (status code) 18 1151 E 1152 ETag header field 9 1154 G 1155 Grammar 1156 entity-tag 9 1157 ETag 9 1158 etagc 9 1159 If-Match 13 1160 If-Modified-Since 15 1161 If-None-Match 14 1162 If-Unmodified-Since 16 1163 Last-Modified 7 1164 opaque-tag 9 1165 weak 9 1167 I 1168 If-Match header field 13 1169 If-Modified-Since header field 15 1170 If-None-Match header field 14 1171 If-Unmodified-Since header field 16 1173 L 1174 Last-Modified header field 7 1176 M 1177 metadata 5 1179 S 1180 selected representation 4 1182 V 1183 validator 5 1184 strong 5 1185 weak 5 1187 Authors' Addresses 1189 Roy T. Fielding (editor) 1190 Adobe Systems Incorporated 1191 345 Park Ave 1192 San Jose, CA 95110 1193 USA 1195 EMail: fielding@gbiv.com 1196 URI: http://roy.gbiv.com/ 1198 Julian F. Reschke (editor) 1199 greenbytes GmbH 1200 Hafenweg 16 1201 Muenster, NW 48155 1202 Germany 1204 EMail: julian.reschke@greenbytes.de 1205 URI: http://greenbytes.de/tech/webdav/