idnits 2.17.1 draft-ietf-httpbis-p4-conditional-22.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 23, 2013) is 4079 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-22 == Outdated reference: A later version (-26) exists of draft-ietf-httpbis-p2-semantics-22 == Outdated reference: A later version (-26) exists of draft-ietf-httpbis-p5-range-22 == Outdated reference: A later version (-26) exists of draft-ietf-httpbis-p6-cache-22 -- 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: August 27, 2013 February 23, 2013 8 Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests 9 draft-ietf-httpbis-p4-conditional-22 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.3. 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 27, 2013. 50 Copyright Notice 52 Copyright (c) 2013 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 . . . . . . . . . . . . . . . . . . . . . . . . . 16 99 4. Status Code Definitions . . . . . . . . . . . . . . . . . . . 17 100 4.1. 304 Not Modified . . . . . . . . . . . . . . . . . . . . . 17 101 4.2. 412 Precondition Failed . . . . . . . . . . . . . . . . . 17 102 5. Evaluation and Precedence . . . . . . . . . . . . . . . . . . 17 103 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 20 104 6.1. Status Code Registration . . . . . . . . . . . . . . . . . 20 105 6.2. Header Field Registration . . . . . . . . . . . . . . . . 20 106 7. Security Considerations . . . . . . . . . . . . . . . . . . . 20 107 8. Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . 21 108 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 21 109 9.1. Normative References . . . . . . . . . . . . . . . . . . . 21 110 9.2. Informative References . . . . . . . . . . . . . . . . . . 22 111 Appendix A. Changes from RFC 2616 . . . . . . . . . . . . . . . . 22 112 Appendix B. Imported ABNF . . . . . . . . . . . . . . . . . . . . 22 113 Appendix C. Collected ABNF . . . . . . . . . . . . . . . . . . . 23 114 Appendix D. Change Log (to be removed by RFC Editor before 115 publication) . . . . . . . . . . . . . . . . . . . . 23 116 D.1. Since draft-ietf-httpbis-p4-conditional-19 . . . . . . . . 23 117 D.2. Since draft-ietf-httpbis-p4-conditional-20 . . . . . . . . 24 118 D.3. Since draft-ietf-httpbis-p4-conditional-21 . . . . . . . . 24 119 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 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 are evaluated by comparing the validators provided in the conditional 150 request header fields to the current validators for the selected 151 representation in the order defined by Section 5. 153 1.1. Conformance and Error Handling 155 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 156 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 157 document are to be interpreted as described in [RFC2119]. 159 Conformance criteria and considerations regarding error handling are 160 defined in Section 2.5 of [Part1]. 162 1.2. Syntax Notation 164 This specification uses the Augmented Backus-Naur Form (ABNF) 165 notation of [RFC5234] with the list rule extension defined in Section 166 1.2 of [Part1]. Appendix B describes rules imported from other 167 documents. Appendix C shows the collected ABNF with the list rule 168 expanded. 170 2. Validators 172 This specification defines two forms of metadata that are commonly 173 used to observe resource state and test for preconditions: 174 modification dates (Section 2.2) and opaque entity tags 175 (Section 2.3). Additional metadata that reflects resource state has 176 been defined by various extensions of HTTP, such as WebDAV [RFC4918], 177 that are beyond the scope of this specification. A resource metadata 178 value is referred to as a "validator" when it is used within a 179 precondition. 181 2.1. Weak versus Strong 183 Validators come in two flavors: strong or weak. Weak validators are 184 easy to generate but are far less useful for comparisons. Strong 185 validators are ideal for comparisons but can be very difficult (and 186 occasionally impossible) to generate efficiently. Rather than impose 187 that all forms of resource adhere to the same strength of validator, 188 HTTP exposes the type of validator in use and imposes restrictions on 189 when weak validators can be used as preconditions. 191 A "strong validator" is representation metadata that changes value 192 whenever a change occurs to the representation data that would be 193 observable in the payload body of a 200 (OK) response to GET. 195 A strong validator might change for other reasons, such as when a 196 semantically significant part of the representation metadata is 197 changed (e.g., Content-Type), but it is in the best interests of the 198 origin server to only change the value when it is necessary to 199 invalidate the stored responses held by remote caches and authoring 200 tools. A strong validator is unique across all representations of a 201 given resource, such that no two representations of that resource can 202 share the same validator unless their representation data is 203 identical. 205 Cache entries might persist for arbitrarily long periods, regardless 206 of expiration times. Thus, a cache might attempt to validate an 207 entry using a validator that it obtained in the distant past. A 208 strong validator is unique across all versions of all representations 209 associated with a particular resource over time. However, there is 210 no implication of uniqueness across representations of different 211 resources (i.e., the same strong validator might be in use for 212 representations of multiple resources at the same time and does not 213 imply that those representations are equivalent). 215 There are a variety of strong validators used in practice. The best 216 are based on strict revision control, wherein each change to a 217 representation always results in a unique node name and revision 218 identifier being assigned before the representation is made 219 accessible to GET. A collision-resistant hash function applied to 220 the representation data is also sufficient if the data is available 221 prior to the response header fields being sent and the digest does 222 not need to be recalculated every time a validation request is 223 received. However, if a resource has distinct representations that 224 differ only in their metadata, such as might occur with content 225 negotiation over media types that happen to share the same data 226 format, then the origin server SHOULD incorporate additional 227 information in the validator to distinguish those representations and 228 avoid confusing cache behavior. 230 In contrast, a "weak validator" is representation metadata that might 231 not change for every change to the representation data. This 232 weakness might be due to limitations in how the value is calculated, 233 such as clock resolution or an inability to ensure uniqueness for all 234 possible representations of the resource, or due to a desire by the 235 resource owner to group representations by some self-determined set 236 of equivalency rather than unique sequences of data. An origin 237 server SHOULD change a weak entity-tag whenever it considers prior 238 representations to be unacceptable as a substitute for the current 239 representation. In other words, a weak entity-tag ought to change 240 whenever the origin server wants caches to invalidate old responses. 242 For example, the representation of a weather report that changes in 243 content every second, based on dynamic measurements, might be grouped 244 into sets of equivalent representations (from the origin server's 245 perspective) with the same weak validator in order to allow cached 246 representations to be valid for a reasonable period of time (perhaps 247 adjusted dynamically based on server load or weather quality). 248 Likewise, a representation's modification time, if defined with only 249 one-second resolution, might be a weak validator if it is possible 250 for the representation to be modified twice during a single second 251 and retrieved between those modifications. 253 Likewise, a validator is weak if it is shared by two or more 254 representations of a given resource at the same time, unless those 255 representations have identical representation data. For example, if 256 the origin server sends the same validator for a representation with 257 a gzip content coding applied as it does for a representation with no 258 content coding, then that validator is weak. However, two 259 simultaneous representations might share the same strong validator if 260 they differ only in the representation metadata, such as when two 261 different media types are available for the same representation data. 263 A "use" of a validator occurs when either a client generates a 264 request and includes the validator in a precondition or when a server 265 compares two validators. Weak validators are only usable in contexts 266 that do not depend on exact equality of the representation data. 267 Strong validators are usable and preferred for all conditional 268 requests, including cache validation, partial content ranges, and 269 "lost update" avoidance. 271 2.2. Last-Modified 273 The "Last-Modified" header field in a response provides a timestamp 274 indicating the date and time at which the origin server believes the 275 selected representation was last modified, as determined at the 276 conclusion of handling the request. 278 Last-Modified = HTTP-date 280 An example of its use is 282 Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT 284 2.2.1. Generation 286 Origin servers SHOULD send Last-Modified for any selected 287 representation for which a last modification date can be reasonably 288 and consistently determined, since its use in conditional requests 289 and evaluating cache freshness ([Part6]) results in a substantial 290 reduction of HTTP traffic on the Internet and can be a significant 291 factor in improving service scalability and reliability. 293 A representation is typically the sum of many parts behind the 294 resource interface. The last-modified time would usually be the most 295 recent time that any of those parts were changed. How that value is 296 determined for any given resource is an implementation detail beyond 297 the scope of this specification. What matters to HTTP is how 298 recipients of the Last-Modified header field can use its value to 299 make conditional requests and test the validity of locally cached 300 responses. 302 An origin server SHOULD obtain the Last-Modified value of the 303 representation as close as possible to the time that it generates the 304 Date field value for its response. This allows a recipient to make 305 an accurate assessment of the representation's modification time, 306 especially if the representation changes near the time that the 307 response is generated. 309 An origin server with a clock MUST NOT send a Last-Modified date that 310 is later than the server's time of message origination (Date). If 311 the last modification time is derived from implementation-specific 312 metadata that evaluates to some time in the future, according to the 313 origin server's clock, then the origin server MUST replace that value 314 with the message origination date. This prevents a future 315 modification date from having an adverse impact on cache validation. 317 An origin server without a clock MUST NOT assign Last-Modified values 318 to a response unless these values were associated with the resource 319 by some other system or user with a reliable clock. 321 2.2.2. Comparison 323 A Last-Modified time, when used as a validator in a request, is 324 implicitly weak unless it is possible to deduce that it is strong, 325 using the following rules: 327 o The validator is being compared by an origin server to the actual 328 current validator for the representation and, 330 o That origin server reliably knows that the associated 331 representation did not change twice during the second covered by 332 the presented validator. 334 or 336 o The validator is about to be used by a client in an If-Modified- 337 Since, If-Unmodified-Since header field, because the client has a 338 cache entry, or If-Range for the associated representation, and 340 o That cache entry includes a Date value, which gives the time when 341 the origin server sent the original response, and 343 o The presented Last-Modified time is at least 60 seconds before the 344 Date value. 346 or 348 o The validator is being compared by an intermediate cache to the 349 validator stored in its cache entry for the representation, and 351 o That cache entry includes a Date value, which gives the time when 352 the origin server sent the original response, and 354 o The presented Last-Modified time is at least 60 seconds before the 355 Date value. 357 This method relies on the fact that if two different responses were 358 sent by the origin server during the same second, but both had the 359 same Last-Modified time, then at least one of those responses would 360 have a Date value equal to its Last-Modified time. The arbitrary 60- 361 second limit guards against the possibility that the Date and Last- 362 Modified values are generated from different clocks, or at somewhat 363 different times during the preparation of the response. An 364 implementation MAY use a value larger than 60 seconds, if it is 365 believed that 60 seconds is too short. 367 2.3. ETag 369 The "ETag" header field in a response provides the current entity-tag 370 for the selected representation, as determined at the conclusion of 371 handling the request. An entity-tag is an opaque validator for 372 differentiating between multiple representations of the same 373 resource, regardless of whether those multiple representations are 374 due to resource state changes over time, content negotiation 375 resulting in multiple representations being valid at the same time, 376 or both. An entity-tag consists of an opaque quoted string, possibly 377 prefixed by a weakness indicator. 379 ETag = entity-tag 381 entity-tag = [ weak ] opaque-tag 382 weak = %x57.2F ; "W/", case-sensitive 383 opaque-tag = DQUOTE *etagc DQUOTE 384 etagc = %x21 / %x23-7E / obs-text 385 ; VCHAR except double quotes, plus obs-text 387 Note: Previously, opaque-tag was defined to be a quoted-string 388 ([RFC2616], Section 3.11), thus some recipients might perform 389 backslash unescaping. Servers therefore ought to avoid backslash 390 characters in entity tags. 392 An entity-tag can be more reliable for validation than a modification 393 date in situations where it is inconvenient to store modification 394 dates, where the one-second resolution of HTTP date values is not 395 sufficient, or where modification dates are not consistently 396 maintained. 398 Examples: 400 ETag: "xyzzy" 401 ETag: W/"xyzzy" 402 ETag: "" 404 An entity-tag can be either a weak or strong validator, with strong 405 being the default. If an origin server provides an entity-tag for a 406 representation and the generation of that entity-tag does not satisfy 407 all of the characteristics of a strong validator (Section 2.1), then 408 the origin server MUST mark the entity-tag as weak by prefixing its 409 opaque value with "W/" (case-sensitive). 411 2.3.1. Generation 413 The principle behind entity-tags is that only the service author 414 knows the implementation of a resource well enough to select the most 415 accurate and efficient validation mechanism for that resource, and 416 that any such mechanism can be mapped to a simple sequence of octets 417 for easy comparison. Since the value is opaque, there is no need for 418 the client to be aware of how each entity-tag is constructed. 420 For example, a resource that has implementation-specific versioning 421 applied to all changes might use an internal revision number, perhaps 422 combined with a variance identifier for content negotiation, to 423 accurately differentiate between representations. Other 424 implementations might use a collision-resistant hash of 425 representation content, a combination of various filesystem 426 attributes, or a modification timestamp that has sub-second 427 resolution. 429 Origin servers SHOULD send ETag for any selected representation for 430 which detection of changes can be reasonably and consistently 431 determined, since the entity-tag's use in conditional requests and 432 evaluating cache freshness ([Part6]) can result in a substantial 433 reduction of HTTP network traffic and can be a significant factor in 434 improving service scalability and reliability. 436 2.3.2. Comparison 438 There are two entity-tag comparison functions, depending on whether 439 the comparison context allows the use of weak validators or not: 441 o Strong comparison: two entity-tags are equivalent if both are not 442 weak and their opaque-tags match character-by-character. 444 o Weak comparison: two entity-tags are equivalent if their opaque- 445 tags match character-by-character, regardless of either or both 446 being tagged as "weak". 448 The example below shows the results for a set of entity-tag pairs, 449 and both the weak and strong comparison function results: 451 +--------+--------+-------------------+-----------------+ 452 | ETag 1 | ETag 2 | Strong Comparison | Weak Comparison | 453 +--------+--------+-------------------+-----------------+ 454 | W/"1" | W/"1" | no match | match | 455 | W/"1" | W/"2" | no match | no match | 456 | W/"1" | "1" | no match | match | 457 | "1" | "1" | match | match | 458 +--------+--------+-------------------+-----------------+ 460 2.3.3. Example: Entity-tags Varying on Content-Negotiated Resources 462 Consider a resource that is subject to content negotiation (Section 463 3.4 of [Part2]), and where the representations sent in response to a 464 GET request vary based on the Accept-Encoding request header field 465 (Section 5.3.4 of [Part2]): 467 >> Request: 469 GET /index HTTP/1.1 470 Host: www.example.com 471 Accept-Encoding: gzip 473 In this case, the response might or might not use the gzip content 474 coding. If it does not, the response might look like: 476 >> Response: 478 HTTP/1.1 200 OK 479 Date: Thu, 26 Mar 2010 00:05:00 GMT 480 ETag: "123-a" 481 Content-Length: 70 482 Vary: Accept-Encoding 483 Content-Type: text/plain 485 Hello World! 486 Hello World! 487 Hello World! 488 Hello World! 489 Hello World! 491 An alternative representation that does use gzip content coding would 492 be: 494 >> Response: 496 HTTP/1.1 200 OK 497 Date: Thu, 26 Mar 2010 00:05:00 GMT 498 ETag: "123-b" 499 Content-Length: 43 500 Vary: Accept-Encoding 501 Content-Type: text/plain 502 Content-Encoding: gzip 504 ...binary data... 506 Note: Content codings are a property of the representation, so 507 therefore an entity-tag of an encoded representation has to be 508 distinct from an unencoded representation to prevent conflicts 509 during cache updates and range requests. In contrast, transfer 510 codings (Section 4 of [Part1]) apply only during message transfer 511 and do not require distinct entity-tags. 513 2.4. When to Use Entity-tags and Last-Modified Dates 515 We adopt a set of rules and recommendations for origin servers, 516 clients, and caches regarding when various validator types ought to 517 be used, and for what purposes. 519 In 200 (OK) responses to GET or HEAD, an origin server: 521 o SHOULD send an entity-tag validator unless it is not feasible to 522 generate one. 524 o MAY send a weak entity-tag instead of a strong entity-tag, if 525 performance considerations support the use of weak entity-tags, or 526 if it is unfeasible to send a strong entity-tag. 528 o SHOULD send a Last-Modified value if it is feasible to send one. 530 In other words, the preferred behavior for an origin server is to 531 send both a strong entity-tag and a Last-Modified value in successful 532 responses to a retrieval request. 534 A client: 536 o MUST use that entity-tag in any cache-conditional request (using 537 If-Match or If-None-Match) if an entity-tag has been provided by 538 the origin server. 540 o SHOULD use the Last-Modified value in non-subrange cache- 541 conditional requests (using If-Modified-Since) if only a Last- 542 Modified value has been provided by the origin server. 544 o MAY use the Last-Modified value in subrange cache-conditional 545 requests (using If-Unmodified-Since) if only a Last-Modified value 546 has been provided by an HTTP/1.0 origin server. The user agent 547 SHOULD provide a way to disable this, in case of difficulty. 549 o SHOULD use both validators in cache-conditional requests if both 550 an entity-tag and a Last-Modified value have been provided by the 551 origin server. This allows both HTTP/1.0 and HTTP/1.1 caches to 552 respond appropriately. 554 3. Precondition Header Fields 556 This section defines the syntax and semantics of HTTP/1.1 header 557 fields for applying preconditions on requests. Section 5 defines 558 when the preconditions are applied and the order of evaluation when 559 more than one precondition is present. 561 3.1. If-Match 563 The "If-Match" header field can be used to make a request method 564 conditional on the current existence or value of an entity-tag for 565 one or more representations of the target resource. 567 If-Match is generally useful for resource update requests, such as 568 PUT requests, as a means for protecting against accidental overwrites 569 when multiple clients are acting in parallel on the same resource 570 (i.e., the "lost update" problem). An If-Match field-value of "*" 571 places the precondition on the existence of any current 572 representation for the target resource. 574 If-Match = "*" / 1#entity-tag 576 The If-Match condition is met if and only if any of the entity-tags 577 listed in the If-Match field value match the entity-tag of the 578 selected representation using the weak comparison function (as per 579 Section 2.3.2), or if "*" is given and any current representation 580 exists for the target resource. 582 If the condition is met, the server MAY perform the request method. 584 Origin servers MUST NOT perform the requested method if the condition 585 is not met; instead they MUST respond with the 412 (Precondition 586 Failed) status code. 588 Proxy servers using a cached response as the selected representation 589 MUST NOT perform the requested method if the condition is not met; 590 instead, they MUST forward the request towards the origin server. 592 Examples: 594 If-Match: "xyzzy" 595 If-Match: "xyzzy", "r2d2xxxx", "c3piozzzz" 596 If-Match: * 598 3.2. If-None-Match 600 The "If-None-Match" header field can be used to make a request method 601 conditional on not matching any of the current entity-tag values for 602 representations of the target resource. 604 If-None-Match is primarily used in conditional GET requests to enable 605 efficient updates of cached information with a minimum amount of 606 transaction overhead. A client that has one or more representations 607 previously obtained from the target resource can send If-None-Match 608 with a list of the associated entity-tags in the hope of receiving a 609 304 (Not Modified) response if at least one of those representations 610 matches the selected representation. 612 If-None-Match can also be used with a value of "*" to prevent an 613 unsafe request method (e.g., PUT) from inadvertently modifying an 614 existing representation of the target resource when the client 615 believes that the resource does not have a current representation. 616 This is a variation on the "lost update" problem that might arise if 617 more than one client attempts to create an initial representation for 618 the target resource. 620 If-None-Match = "*" / 1#entity-tag 622 The If-None-Match condition is met if and only if none of the entity- 623 tags listed in the If-None-Match field value match the entity-tag of 624 the selected representation using the weak comparison function (as 625 per Section 2.3.2), or if "*" is given and no current representation 626 exists for that resource. 628 If the condition is not met, the server MUST NOT perform the 629 requested method. Instead, if the request method was GET or HEAD, 630 the server SHOULD respond with a 304 (Not Modified) status code, 631 including the cache-related header fields (particularly ETag) of the 632 selected representation that has a matching entity-tag. For all 633 other request methods, the server MUST respond with a 412 634 (Precondition Failed) status code when the condition is not met. 636 If the condition is met, the server MAY perform the requested method 637 and MUST ignore any If-Modified-Since header field(s) in the request. 638 That is, if no entity-tags match, then the server MUST NOT send a 304 639 (Not Modified) response. 641 Examples: 643 If-None-Match: "xyzzy" 644 If-None-Match: W/"xyzzy" 645 If-None-Match: "xyzzy", "r2d2xxxx", "c3piozzzz" 646 If-None-Match: W/"xyzzy", W/"r2d2xxxx", W/"c3piozzzz" 647 If-None-Match: * 649 3.3. If-Modified-Since 651 The "If-Modified-Since" header field can be used with GET or HEAD to 652 make the method conditional by modification date: if the selected 653 representation has not been modified since the time specified in this 654 field, then do not perform the request method; instead, respond as 655 detailed below. 657 If-Modified-Since = HTTP-date 659 An example of the field is: 661 If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT 663 A GET method with an If-Modified-Since header field and no Range 664 header field requests that the selected representation be transferred 665 only if it has been modified since the date given by the If-Modified- 666 Since header field. The algorithm for determining this includes the 667 following cases: 669 1. If the request would normally result in anything other than a 200 670 (OK) status code, or if the passed If-Modified-Since date is 671 invalid, the response is exactly the same as for a normal GET. A 672 date that is later than the server's current time is invalid. 674 2. If the selected representation has been modified since the If- 675 Modified-Since date, the response is exactly the same as for a 676 normal GET. 678 3. If the selected representation has not been modified since a 679 valid If-Modified-Since date, the server SHOULD send a 304 (Not 680 Modified) response. 682 The two purposes of this feature are to allow efficient updates of 683 cached information, with a minimum amount of transaction overhead, 684 and to limit the scope of a web traversal to resources that have 685 recently changed. 687 When used for cache updates, a cache will typically use the value of 688 the cached message's Last-Modified field to generate the field value 689 of If-Modified-Since. This behavior is most interoperable for cases 690 where clocks are poorly synchronized or when the server has chosen to 691 only honor exact timestamp matches (due to a problem with Last- 692 Modified dates that appear to go "back in time" when the origin 693 server's clock is corrected or a representation is restored from an 694 archived backup). However, caches occasionally generate the field 695 value based on other data, such as the Date header field of the 696 cached message or the local clock time that the message was received, 697 particularly when the cached message does not contain a Last-Modified 698 field. 700 When used for limiting the scope of retrieval to a recent time 701 window, a user agent will generate an If-Modified-Since field value 702 based on either its own local clock or a Date header field received 703 from the server during a past run. Origin servers that choose an 704 exact timestamp match based on the selected representation's Last- 705 Modified field will not be able to help the user agent limit its data 706 transfers to only those changed during the specified window. 708 Note: If a client uses an arbitrary date in the If-Modified-Since 709 header field instead of a date taken from a Last-Modified or Date 710 header field from the origin server, the client ought to be aware 711 that its date will be interpreted according to the server's 712 understanding of time. 714 3.4. If-Unmodified-Since 716 The "If-Unmodified-Since" header field can be used to make a request 717 method conditional by modification date: if the selected 718 representation has been modified since the time specified in this 719 field, then the server MUST NOT perform the requested operation and 720 MUST instead respond with the 412 (Precondition Failed) status code. 721 If the selected representation has not been modified since the time 722 specified in this field, the server MAY perform the request. 724 If-Unmodified-Since = HTTP-date 726 An example of the field is: 728 If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT 730 A server MUST ignore the If-Unmodified-Since header field if the 731 received value is not a valid HTTP-date. 733 3.5. If-Range 735 The "If-Range" header field provides a special conditional request 736 mechanism that is similar to If-Match and If-Unmodified-Since but 737 specific to range requests. If-Range is defined in Section 3.2 of 738 [Part5]. 740 4. Status Code Definitions 742 4.1. 304 Not Modified 744 The 304 (Not Modified) status code indicates that a conditional GET 745 request has been received and would have resulted in a 200 (OK) 746 response if it were not for the fact that the condition has evaluated 747 to false. In other words, there is no need for the server to 748 transfer a representation of the target resource because the request 749 indicates that the client, which made the request conditional, 750 already has a valid representation; the server is therefore 751 redirecting the client to make use of that stored representation as 752 if it were the payload of a 200 (OK) response. 754 The server generating a 304 response MUST generate any of the 755 following header fields that would have been sent in a 200 (OK) 756 response to the same request: Cache-Control, Content-Location, ETag, 757 Expires, and Vary. 759 Since the goal of a 304 response is to minimize information transfer 760 when the recipient already has one or more cached representations, a 761 sender SHOULD NOT generate representation metadata other than the 762 above listed fields unless said metadata exists for the purpose of 763 guiding cache updates (e.g., Last-Modified might be useful if the 764 response does not have an ETag field). 766 Requirements on a cache that receives a 304 response are defined in 767 Section 4.2.1 of [Part6]. If the conditional request originated with 768 an outbound client, such as a user agent with its own cache sending a 769 conditional GET to a shared proxy, then the proxy SHOULD forward the 770 304 response to that client. 772 A 304 response cannot contain a message-body; it is always terminated 773 by the first empty line after the header fields. 775 4.2. 412 Precondition Failed 777 The 412 (Precondition Failed) status code indicates that one or more 778 preconditions given in the request header fields evaluated to false 779 when tested on the server. This response code allows the client to 780 place preconditions on the current resource state (its current 781 representations and metadata) and thus prevent the request method 782 from being applied if the target resource is in an unexpected state. 784 5. Evaluation and Precedence 786 For each conditional request, a server MUST evaluate the request 787 preconditions after it has successfully performed its normal request 788 checks (i.e., just before it would perform the action associated with 789 the request method). Preconditions are ignored if the server 790 determines that an error or redirect response applies before they are 791 evaluated. Otherwise, the evaluation depends on both the method 792 semantics and the choice of conditional. 794 A conditional request header field that is designed specifically for 795 cache validation, which includes If-None-Match and If-Modified-Since 796 when used in a GET or HEAD request, allows cached representations to 797 be refreshed without repeatedly transferring data already held by the 798 client. Evaluating to false is thus an indication that the client 799 can continue to use its local copy of the selected representation, as 800 indicated by the server generating a 304 (Not Modified) response that 801 includes only those header fields useful for refreshing the cached 802 representation. 804 All other conditionals are intended to signal failure when the 805 precondition evaluates to false. For example, an If-Match 806 conditional sent with a state-changing method (e.g., POST, PUT, 807 DELETE) is intended to prevent the request from taking effect on the 808 target resource if the resource state does not match the expected 809 state. In other words, evaluating the condition to false means that 810 the resource has been changed by some other client, perhaps by 811 another user attempting to edit the same resource, and thus 812 preventing the request from being applied saves the client from 813 overwriting some other client's work. This result is indicated by 814 the server generating a 412 (Precondition Failed) response. 816 The conditional request header fields defined by this specification 817 are ignored for request methods that never involve the selection or 818 modification of a selected representation (e.g., CONNECT, OPTIONS, 819 and TRACE). Other conditional request header fields, defined by 820 extensions to HTTP, might place conditions on the state of the target 821 resource in general, or on a group of resources. For instance, the 822 If header field in WebDAV can make a request conditional on various 823 aspects (such as locks) of multiple resources ([RFC4918], Section 824 10.4). 826 When more than one conditional request header field is present in a 827 request, the order in which the fields are evaluated becomes 828 important. In practice, the fields defined in this document are 829 consistently implemented in a single, logical order, due to the fact 830 that entity tags are presumed to be more accurate than date 831 validators. For example, the only reason to send both If-Modified- 832 Since and If-None-Match in the same GET request is to support 833 intermediary caches that might not have implemented If-None-Match, so 834 it makes sense to ignore the If-Modified-Since when entity tags are 835 understood and available for the selected representation. 837 The general rule of conditional precedence is that exact match 838 conditions are evaluated before cache-validating conditions and, 839 within that order, last-modified conditions are only evaluated if the 840 corresponding entity tag condition is not present (or not applicable 841 because the selected representation does not have an entity tag). 843 Specifically, the fields defined by this specification are evaluated 844 as follows: 846 1. When If-Match is present, evaluate it: 848 * if true, continue to step 3 850 * if false, respond 412 (Precondition Failed) 852 2. When If-Match is not present and If-Unmodified-Since is present, 853 evaluate it: 855 * if true, continue to step 3 857 * if false, respond 412 (Precondition Failed) 859 3. When If-None-Match is present, evaluate it: 861 * if true, continue to step 5 863 * if false for GET/HEAD, respond 304 (Not Modified) 865 * if false for other methods, respond 412 (Precondition Failed) 867 4. When the method is GET or HEAD, If-None-Match is not present, and 868 If-Modified-Since is present, evaluate it: 870 * if true, continue to step 5 872 * if false, respond 304 (Not Modified) 874 5. When the method is GET and both Range and If-Range are present, 875 evaluate If-Range: 877 * if the validator matches and the Range specification is 878 applicable to the selected representation, respond 206 879 (Partial Content) [Part5] 881 6. Otherwise, 883 * all conditions are met, so perform the requested action and 884 respond according to its success or failure. 886 Any extension to HTTP/1.1 that defines additional conditional request 887 header fields ought to define its own expectations regarding the 888 order for evaluating such fields in relation to those defined in this 889 document and other conditionals that might be found in practice. 891 6. IANA Considerations 893 6.1. Status Code Registration 895 The HTTP Status Code Registry located at 896 shall be updated 897 with the registrations below: 899 +-------+---------------------+-------------+ 900 | Value | Description | Reference | 901 +-------+---------------------+-------------+ 902 | 304 | Not Modified | Section 4.1 | 903 | 412 | Precondition Failed | Section 4.2 | 904 +-------+---------------------+-------------+ 906 6.2. Header Field Registration 908 The Message Header Field Registry located at shall be 910 updated with the permanent registrations below (see [BCP90]): 912 +---------------------+----------+----------+-------------+ 913 | Header Field Name | Protocol | Status | Reference | 914 +---------------------+----------+----------+-------------+ 915 | ETag | http | standard | Section 2.3 | 916 | If-Match | http | standard | Section 3.1 | 917 | If-Modified-Since | http | standard | Section 3.3 | 918 | If-None-Match | http | standard | Section 3.2 | 919 | If-Unmodified-Since | http | standard | Section 3.4 | 920 | Last-Modified | http | standard | Section 2.2 | 921 +---------------------+----------+----------+-------------+ 923 The change controller is: "IETF (iesg@ietf.org) - Internet 924 Engineering Task Force". 926 7. Security Considerations 928 This section is meant to inform developers, information providers, 929 and users of known security concerns specific to the HTTP/1.1 930 conditional request mechanisms. More general security considerations 931 are addressed in HTTP messaging [Part1] and semantics [Part2]. 933 The validators defined by this specification are not intended to 934 ensure the validity of a representation, guard against malicious 935 changes, or detect man-in-the-middle attacks. At best, they enable 936 more efficient cache updates and optimistic concurrent writes when 937 all participants are behaving nicely. At worst, the conditions will 938 fail and the client will receive a response that is no more harmful 939 than an HTTP exchange without conditional requests. 941 An entity-tag can be abused in ways that create privacy risks. For 942 example, a site might deliberately construct a semantically invalid 943 entity-tag that is unique to the user or user agent, send it in a 944 cacheable response with a long freshness time, and then read that 945 entity-tag in later conditional requests as a means of re-identifying 946 that user or user agent. Such an identifying tag would become a 947 persistent identifier for as long as the user agent retained the 948 original cache entry. User agents that cache representations ought 949 to ensure that the cache is cleared or replaced whenever the user 950 performs privacy-maintaining actions, such as clearing stored cookies 951 or changing to a private browsing mode. 953 8. Acknowledgments 955 See Section 9 of [Part1]. 957 9. References 959 9.1. Normative References 961 [Part1] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer 962 Protocol (HTTP/1.1): Message Syntax and Routing", 963 draft-ietf-httpbis-p1-messaging-22 (work in progress), 964 February 2013. 966 [Part2] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer 967 Protocol (HTTP/1.1): Semantics and Content", 968 draft-ietf-httpbis-p2-semantics-22 (work in progress), 969 February 2013. 971 [Part5] Fielding, R., Ed., Lafon, Y., Ed., and J. Reschke, Ed., 972 "Hypertext Transfer Protocol (HTTP/1.1): Range Requests", 973 draft-ietf-httpbis-p5-range-22 (work in progress), 974 February 2013. 976 [Part6] Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, 977 Ed., "Hypertext Transfer Protocol (HTTP/1.1): Caching", 978 draft-ietf-httpbis-p6-cache-22 (work in progress), 979 February 2013. 981 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 982 Requirement Levels", BCP 14, RFC 2119, March 1997. 984 [RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax 985 Specifications: ABNF", STD 68, RFC 5234, January 2008. 987 9.2. Informative References 989 [BCP90] Klyne, G., Nottingham, M., and J. Mogul, "Registration 990 Procedures for Message Header Fields", BCP 90, RFC 3864, 991 September 2004. 993 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 994 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 995 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 997 [RFC4918] Dusseault, L., Ed., "HTTP Extensions for Web Distributed 998 Authoring and Versioning (WebDAV)", RFC 4918, June 2007. 1000 Appendix A. Changes from RFC 2616 1002 The definition of validator weakness has been expanded and clarified. 1003 (Section 2.1) 1005 Weak entity-tags are now allowed in all requests except range 1006 requests (Sections 2.1 and 3.2). 1008 The ETag header field ABNF has been changed to not use quoted-string, 1009 thus avoiding escaping issues. (Section 2.3) 1011 ETag is defined to provide an entity tag for the selected 1012 representation, thereby clarifying what it applies to in various 1013 situations (such as a PUT response). (Section 2.3) 1015 The precedence for evaluation of conditional requests has been 1016 defined. (Section 5) 1018 Appendix B. Imported ABNF 1020 The following core rules are included by reference, as defined in 1021 Appendix B.1 of [RFC5234]: ALPHA (letters), CR (carriage return), 1022 CRLF (CR LF), CTL (controls), DIGIT (decimal 0-9), DQUOTE (double 1023 quote), HEXDIG (hexadecimal 0-9/A-F/a-f), LF (line feed), OCTET (any 1024 8-bit sequence of data), SP (space), and VCHAR (any visible US-ASCII 1025 character). 1027 The rules below are defined in [Part1]: 1029 OWS = 1030 obs-text = 1032 The rules below are defined in other parts: 1034 HTTP-date = 1036 Appendix C. Collected ABNF 1038 ETag = entity-tag 1040 HTTP-date = 1042 If-Match = "*" / ( *( "," OWS ) entity-tag *( OWS "," [ OWS 1043 entity-tag ] ) ) 1044 If-Modified-Since = HTTP-date 1045 If-None-Match = "*" / ( *( "," OWS ) entity-tag *( OWS "," [ OWS 1046 entity-tag ] ) ) 1047 If-Unmodified-Since = HTTP-date 1049 Last-Modified = HTTP-date 1051 OWS = 1053 entity-tag = [ weak ] opaque-tag 1054 etagc = "!" / %x23-7E ; '#'-'~' 1055 / obs-text 1057 obs-text = 1058 opaque-tag = DQUOTE *etagc DQUOTE 1060 weak = %x57.2F ; W/ 1062 Appendix D. Change Log (to be removed by RFC Editor before publication) 1064 Changes up to the first Working Group Last Call draft are summarized 1065 in . 1068 D.1. Since draft-ietf-httpbis-p4-conditional-19 1070 Closed issues: 1072 o : "Need to 1073 clarify eval order/interaction of conditional headers" 1075 o : "Required 1076 headers on 304 and 206" 1078 o : "Optionality 1079 of Conditional Request Support" 1081 o : "ETags and 1082 Conditional Requests" 1084 o : "ABNF 1085 requirements for recipients" 1087 o : "Rare cases" 1089 o : "Conditional 1090 Request Security Considerations" 1092 o : "If-Modified- 1093 Since lacks definition for method != GET" 1095 o : "refactor 1096 conditional header field descriptions" 1098 D.2. Since draft-ietf-httpbis-p4-conditional-20 1100 o Conformance criteria and considerations regarding error handling 1101 are now defined in Part 1. 1103 D.3. Since draft-ietf-httpbis-p4-conditional-21 1105 Closed issues: 1107 o : "Conditional 1108 GET text" 1110 o : "Optionality 1111 of Conditional Request Support" 1113 o : "unclear prose 1114 in definition of 304" 1116 o : "ETags and 1117 Conneg" 1119 o : "Comparison 1120 function for If-Match and If-None-Match" 1122 o : "304 without 1123 validator" 1125 o : "If-Match and 1126 428" 1128 Index 1130 3 1131 304 Not Modified (status code) 17 1133 4 1134 412 Precondition Failed (status code) 17 1136 E 1137 ETag header field 9 1139 G 1140 Grammar 1141 entity-tag 9 1142 ETag 9 1143 etagc 9 1144 If-Match 13 1145 If-Modified-Since 15 1146 If-None-Match 14 1147 If-Unmodified-Since 16 1148 Last-Modified 7 1149 opaque-tag 9 1150 weak 9 1152 I 1153 If-Match header field 13 1154 If-Modified-Since header field 15 1155 If-None-Match header field 14 1156 If-Unmodified-Since header field 16 1158 L 1159 Last-Modified header field 7 1161 M 1162 metadata 5 1164 S 1165 selected representation 4 1167 V 1168 validator 5 1169 strong 5 1170 weak 5 1172 Authors' Addresses 1174 Roy T. Fielding (editor) 1175 Adobe Systems Incorporated 1176 345 Park Ave 1177 San Jose, CA 95110 1178 USA 1180 EMail: fielding@gbiv.com 1181 URI: http://roy.gbiv.com/ 1183 Julian F. Reschke (editor) 1184 greenbytes GmbH 1185 Hafenweg 16 1186 Muenster, NW 48155 1187 Germany 1189 EMail: julian.reschke@greenbytes.de 1190 URI: http://greenbytes.de/tech/webdav/