idnits 2.17.1 draft-fielding-httpbis-http-conditional-00.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == The document seems to contain a disclaimer for pre-RFC5378 work, but was first submitted on or after 10 November 2008. The disclaimer is usually necessary only for documents that revise or obsolete older RFCs, and that take significant amounts of text from those RFCs. If you can contact all authors of the source material and they are willing to grant the BCP78 rights to the IETF Trust, you can and should remove the disclaimer. Otherwise, the disclaimer is needed and you can ignore this comment. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (March 5, 2018) is 2244 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) == Unused Reference: 'RFC7232' is defined on line 1067, but no explicit reference was found in the text -- Obsolete informational reference (is this intentional?): RFC 2616 (Obsoleted by RFC 7230, RFC 7231, RFC 7232, RFC 7233, RFC 7234, RFC 7235) -- Obsolete informational reference (is this intentional?): RFC 7232 (Obsoleted by RFC 9110) Summary: 0 errors (**), 0 flaws (~~), 3 warnings (==), 3 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Network Working Group R. Fielding, Ed. 3 Internet-Draft Adobe 4 Obsoletes: 7232 (if approved) J. Reschke, Ed. 5 Intended status: Standards Track greenbytes 6 Expires: September 6, 2018 March 5, 2018 8 Hypertext Transfer Protocol (HTTP): Conditional Requests 9 draft-fielding-httpbis-http-conditional-00 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 This document obsoletes RFC 7232. 23 Editorial Note 25 This note is to be removed before publishing as an RFC. 27 _This is a temporary document for the purpose of planning the 28 revisions of RFCs 7230 to 7235. This is not yet an official work 29 item of the HTTP Working Group._ 31 Discussion of this draft takes place on the HTTP working group 32 mailing list (ietf-http-wg@w3.org), which is archived at 33 . 35 Errata for RFC 7232 have been collected at , and an additional issues list 37 lives at . 39 The changes in this draft are summarized in Appendix D.1. 41 Status of This Memo 43 This Internet-Draft is submitted in full conformance with the 44 provisions of BCP 78 and BCP 79. 46 Internet-Drafts are working documents of the Internet Engineering 47 Task Force (IETF). Note that other groups may also distribute 48 working documents as Internet-Drafts. The list of current Internet- 49 Drafts is at https://datatracker.ietf.org/drafts/current/. 51 Internet-Drafts are draft documents valid for a maximum of six months 52 and may be updated, replaced, or obsoleted by other documents at any 53 time. It is inappropriate to use Internet-Drafts as reference 54 material or to cite them other than as "work in progress." 56 This Internet-Draft will expire on September 6, 2018. 58 Copyright Notice 60 Copyright (c) 2018 IETF Trust and the persons identified as the 61 document authors. All rights reserved. 63 This document is subject to BCP 78 and the IETF Trust's Legal 64 Provisions Relating to IETF Documents 65 (https://trustee.ietf.org/license-info) in effect on the date of 66 publication of this document. Please review these documents 67 carefully, as they describe your rights and restrictions with respect 68 to this document. Code Components extracted from this document must 69 include Simplified BSD License text as described in Section 4.e of 70 the Trust Legal Provisions and are provided without warranty as 71 described in the Simplified BSD License. 73 This document may contain material from IETF Documents or IETF 74 Contributions published or made publicly available before November 75 10, 2008. The person(s) controlling the copyright in some of this 76 material may not have granted the IETF Trust the right to allow 77 modifications of such material outside the IETF Standards Process. 78 Without obtaining an adequate license from the person(s) controlling 79 the copyright in such materials, this document may not be modified 80 outside the IETF Standards Process, and derivative works of it may 81 not be created outside the IETF Standards Process, except to format 82 it for publication as an RFC or to translate it into languages other 83 than English. 85 Table of Contents 87 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 88 1.1. Conformance and Error Handling . . . . . . . . . . . . . 4 89 1.2. Syntax Notation . . . . . . . . . . . . . . . . . . . . . 4 90 2. Validators . . . . . . . . . . . . . . . . . . . . . . . . . 4 91 2.1. Weak versus Strong . . . . . . . . . . . . . . . . . . . 5 92 2.2. Last-Modified . . . . . . . . . . . . . . . . . . . . . . 6 93 2.2.1. Generation . . . . . . . . . . . . . . . . . . . . . 7 94 2.2.2. Comparison . . . . . . . . . . . . . . . . . . . . . 7 95 2.3. ETag . . . . . . . . . . . . . . . . . . . . . . . . . . 8 96 2.3.1. Generation . . . . . . . . . . . . . . . . . . . . . 9 97 2.3.2. Comparison . . . . . . . . . . . . . . . . . . . . . 10 98 2.3.3. Example: Entity-Tags Varying on Content-Negotiated 99 Resources . . . . . . . . . . . . . . . . . . . . . . 10 100 2.4. When to Use Entity-Tags and Last-Modified Dates . . . . . 11 101 3. Precondition Header Fields . . . . . . . . . . . . . . . . . 12 102 3.1. If-Match . . . . . . . . . . . . . . . . . . . . . . . . 12 103 3.2. If-None-Match . . . . . . . . . . . . . . . . . . . . . . 13 104 3.3. If-Modified-Since . . . . . . . . . . . . . . . . . . . . 15 105 3.4. If-Unmodified-Since . . . . . . . . . . . . . . . . . . . 16 106 3.5. If-Range . . . . . . . . . . . . . . . . . . . . . . . . 17 107 4. Status Code Definitions . . . . . . . . . . . . . . . . . . . 17 108 4.1. 304 Not Modified . . . . . . . . . . . . . . . . . . . . 17 109 4.2. 412 Precondition Failed . . . . . . . . . . . . . . . . . 18 110 5. Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . 18 111 6. Precedence . . . . . . . . . . . . . . . . . . . . . . . . . 19 112 7. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 20 113 7.1. Status Code Registration . . . . . . . . . . . . . . . . 20 114 7.2. Header Field Registration . . . . . . . . . . . . . . . . 21 115 8. Security Considerations . . . . . . . . . . . . . . . . . . . 21 116 9. References . . . . . . . . . . . . . . . . . . . . . . . . . 22 117 9.1. Normative References . . . . . . . . . . . . . . . . . . 22 118 9.2. Informative References . . . . . . . . . . . . . . . . . 23 119 Appendix A. Changes from RFC 7232 . . . . . . . . . . . . . . . 24 120 Appendix B. Imported ABNF . . . . . . . . . . . . . . . . . . . 24 121 Appendix C. Collected ABNF . . . . . . . . . . . . . . . . . . . 24 122 Appendix D. Change Log . . . . . . . . . . . . . . . . . . . . . 25 123 D.1. Since RFC 7232 . . . . . . . . . . . . . . . . . . . . . 25 124 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 125 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 27 126 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 27 128 1. Introduction 130 Conditional requests are HTTP requests [SEMNTCS] that include one or 131 more header fields indicating a precondition to be tested before 132 applying the method semantics to the target resource. This document 133 defines the HTTP/1.1 conditional request mechanisms in terms of the 134 architecture, syntax notation, and conformance criteria defined in 135 [MESSGNG]. 137 Conditional GET requests are the most efficient mechanism for HTTP 138 cache updates [CACHING]. Conditionals can also be applied to state- 139 changing methods, such as PUT and DELETE, to prevent the "lost 140 update" problem: one client accidentally overwriting the work of 141 another client that has been acting in parallel. 143 Conditional request preconditions are based on the state of the 144 target resource as a whole (its current value set) or the state as 145 observed in a previously obtained representation (one value in that 146 set). A resource might have multiple current representations, each 147 with its own observable state. The conditional request mechanisms 148 assume that the mapping of requests to a "selected representation" 149 (Section 3 of [SEMNTCS]) will be consistent over time if the server 150 intends to take advantage of conditionals. Regardless, if the 151 mapping is inconsistent and the server is unable to select the 152 appropriate representation, then no harm will result when the 153 precondition evaluates to false. 155 The conditional request preconditions defined by this specification 156 (Section 3) are evaluated when applicable to the recipient 157 (Section 5) according to their order of precedence (Section 6). 159 This specification obsoletes RFC 7232, with the changes being 160 summarized in Appendix A. 162 1.1. Conformance and Error Handling 164 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 165 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 166 document are to be interpreted as described in [RFC2119]. 168 Conformance criteria and considerations regarding error handling are 169 defined in Section 2.5 of [MESSGNG]. 171 1.2. Syntax Notation 173 This specification uses the Augmented Backus-Naur Form (ABNF) 174 notation of [RFC5234] with a list extension, defined in Section 7 of 175 [MESSGNG], that allows for compact definition of comma-separated 176 lists using a '#' operator (similar to how the '*' operator indicates 177 repetition). Appendix B describes rules imported from other 178 documents. Appendix C shows the collected grammar with all list 179 operators expanded to standard ABNF notation. 181 2. Validators 183 This specification defines two forms of metadata that are commonly 184 used to observe resource state and test for preconditions: 185 modification dates (Section 2.2) and opaque entity tags 186 (Section 2.3). Additional metadata that reflects resource state has 187 been defined by various extensions of HTTP, such as Web Distributed 188 Authoring and Versioning (WebDAV, [RFC4918]), that are beyond the 189 scope of this specification. A resource metadata value is referred 190 to as a "validator" when it is used within a precondition. 192 2.1. Weak versus Strong 194 Validators come in two flavors: strong or weak. Weak validators are 195 easy to generate but are far less useful for comparisons. Strong 196 validators are ideal for comparisons but can be very difficult (and 197 occasionally impossible) to generate efficiently. Rather than impose 198 that all forms of resource adhere to the same strength of validator, 199 HTTP exposes the type of validator in use and imposes restrictions on 200 when weak validators can be used as preconditions. 202 A "strong validator" is representation metadata that changes value 203 whenever a change occurs to the representation data that would be 204 observable in the payload body of a 200 (OK) response to GET. 206 A strong validator might change for reasons other than a change to 207 the representation data, such as when a semantically significant part 208 of the representation metadata is changed (e.g., Content-Type), but 209 it is in the best interests of the origin server to only change the 210 value when it is necessary to invalidate the stored responses held by 211 remote caches and authoring tools. 213 Cache entries might persist for arbitrarily long periods, regardless 214 of expiration times. Thus, a cache might attempt to validate an 215 entry using a validator that it obtained in the distant past. A 216 strong validator is unique across all versions of all representations 217 associated with a particular resource over time. However, there is 218 no implication of uniqueness across representations of different 219 resources (i.e., the same strong validator might be in use for 220 representations of multiple resources at the same time and does not 221 imply that those representations are equivalent). 223 There are a variety of strong validators used in practice. The best 224 are based on strict revision control, wherein each change to a 225 representation always results in a unique node name and revision 226 identifier being assigned before the representation is made 227 accessible to GET. A collision-resistant hash function applied to 228 the representation data is also sufficient if the data is available 229 prior to the response header fields being sent and the digest does 230 not need to be recalculated every time a validation request is 231 received. However, if a resource has distinct representations that 232 differ only in their metadata, such as might occur with content 233 negotiation over media types that happen to share the same data 234 format, then the origin server needs to incorporate additional 235 information in the validator to distinguish those representations. 237 In contrast, a "weak validator" is representation metadata that might 238 not change for every change to the representation data. This 239 weakness might be due to limitations in how the value is calculated, 240 such as clock resolution, an inability to ensure uniqueness for all 241 possible representations of the resource, or a desire of the resource 242 owner to group representations by some self-determined set of 243 equivalency rather than unique sequences of data. An origin server 244 SHOULD change a weak entity-tag whenever it considers prior 245 representations to be unacceptable as a substitute for the current 246 representation. In other words, a weak entity-tag ought to change 247 whenever the origin server wants caches to invalidate old responses. 249 For example, the representation of a weather report that changes in 250 content every second, based on dynamic measurements, might be grouped 251 into sets of equivalent representations (from the origin server's 252 perspective) with the same weak validator in order to allow cached 253 representations to be valid for a reasonable period of time (perhaps 254 adjusted dynamically based on server load or weather quality). 255 Likewise, a representation's modification time, if defined with only 256 one-second resolution, might be a weak validator if it is possible 257 for the representation to be modified twice during a single second 258 and retrieved between those modifications. 260 Likewise, a validator is weak if it is shared by two or more 261 representations of a given resource at the same time, unless those 262 representations have identical representation data. For example, if 263 the origin server sends the same validator for a representation with 264 a gzip content coding applied as it does for a representation with no 265 content coding, then that validator is weak. However, two 266 simultaneous representations might share the same strong validator if 267 they differ only in the representation metadata, such as when two 268 different media types are available for the same representation data. 270 Strong validators are usable for all conditional requests, including 271 cache validation, partial content ranges, and "lost update" 272 avoidance. Weak validators are only usable when the client does not 273 require exact equality with previously obtained representation data, 274 such as when validating a cache entry or limiting a web traversal to 275 recent changes. 277 2.2. Last-Modified 279 The "Last-Modified" header field in a response provides a timestamp 280 indicating the date and time at which the origin server believes the 281 selected representation was last modified, as determined at the 282 conclusion of handling the request. 284 Last-Modified = HTTP-date 286 An example of its use is 287 Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT 289 2.2.1. Generation 291 An origin server SHOULD send Last-Modified for any selected 292 representation for which a last modification date can be reasonably 293 and consistently determined, since its use in conditional requests 294 and evaluating cache freshness ([CACHING]) results in a substantial 295 reduction of HTTP traffic on the Internet and can be a significant 296 factor in improving service scalability and reliability. 298 A representation is typically the sum of many parts behind the 299 resource interface. The last-modified time would usually be the most 300 recent time that any of those parts were changed. How that value is 301 determined for any given resource is an implementation detail beyond 302 the scope of this specification. What matters to HTTP is how 303 recipients of the Last-Modified header field can use its value to 304 make conditional requests and test the validity of locally cached 305 responses. 307 An origin server SHOULD obtain the Last-Modified value of the 308 representation as close as possible to the time that it generates the 309 Date field value for its response. This allows a recipient to make 310 an accurate assessment of the representation's modification time, 311 especially if the representation changes near the time that the 312 response is generated. 314 An origin server with a clock MUST NOT send a Last-Modified date that 315 is later than the server's time of message origination (Date). If 316 the last modification time is derived from implementation-specific 317 metadata that evaluates to some time in the future, according to the 318 origin server's clock, then the origin server MUST replace that value 319 with the message origination date. This prevents a future 320 modification date from having an adverse impact on cache validation. 322 An origin server without a clock MUST NOT assign Last-Modified values 323 to a response unless these values were associated with the resource 324 by some other system or user with a reliable clock. 326 2.2.2. Comparison 328 A Last-Modified time, when used as a validator in a request, is 329 implicitly weak unless it is possible to deduce that it is strong, 330 using the following rules: 332 o The validator is being compared by an origin server to the actual 333 current validator for the representation and, 335 o That origin server reliably knows that the associated 336 representation did not change twice during the second covered by 337 the presented validator. 339 or 341 o The validator is about to be used by a client in an If-Modified- 342 Since, If-Unmodified-Since, or If-Range header field, because the 343 client has a cache entry for the associated representation, and 345 o That cache entry includes a Date value, which gives the time when 346 the origin server sent the original response, and 348 o The presented Last-Modified time is at least 60 seconds before the 349 Date value. 351 or 353 o The validator is being compared by an intermediate cache to the 354 validator stored in its cache entry for the representation, and 356 o That cache entry includes a Date value, which gives the time when 357 the origin server sent the original response, and 359 o The presented Last-Modified time is at least 60 seconds before the 360 Date value. 362 This method relies on the fact that if two different responses were 363 sent by the origin server during the same second, but both had the 364 same Last-Modified time, then at least one of those responses would 365 have a Date value equal to its Last-Modified time. The arbitrary 366 60-second limit guards against the possibility that the Date and 367 Last-Modified values are generated from different clocks or at 368 somewhat different times during the preparation of the response. An 369 implementation MAY use a value larger than 60 seconds, if it is 370 believed that 60 seconds is too short. 372 2.3. ETag 374 The "ETag" header field in a response provides the current entity-tag 375 for the selected representation, as determined at the conclusion of 376 handling the request. An entity-tag is an opaque validator for 377 differentiating between multiple representations of the same 378 resource, regardless of whether those multiple representations are 379 due to resource state changes over time, content negotiation 380 resulting in multiple representations being valid at the same time, 381 or both. An entity-tag consists of an opaque quoted string, possibly 382 prefixed by a weakness indicator. 384 ETag = entity-tag 386 entity-tag = [ weak ] opaque-tag 387 weak = %x57.2F ; "W/", case-sensitive 388 opaque-tag = DQUOTE *etagc DQUOTE 389 etagc = %x21 / %x23-7E / obs-text 390 ; VCHAR except double quotes, plus obs-text 392 Note: Previously, opaque-tag was defined to be a quoted-string 393 ([RFC2616], Section 3.11); thus, some recipients might perform 394 backslash unescaping. Servers therefore ought to avoid backslash 395 characters in entity tags. 397 An entity-tag can be more reliable for validation than a modification 398 date in situations where it is inconvenient to store modification 399 dates, where the one-second resolution of HTTP date values is not 400 sufficient, or where modification dates are not consistently 401 maintained. 403 Examples: 405 ETag: "xyzzy" 406 ETag: W/"xyzzy" 407 ETag: "" 409 An entity-tag can be either a weak or strong validator, with strong 410 being the default. If an origin server provides an entity-tag for a 411 representation and the generation of that entity-tag does not satisfy 412 all of the characteristics of a strong validator (Section 2.1), then 413 the origin server MUST mark the entity-tag as weak by prefixing its 414 opaque value with "W/" (case-sensitive). 416 2.3.1. Generation 418 The principle behind entity-tags is that only the service author 419 knows the implementation of a resource well enough to select the most 420 accurate and efficient validation mechanism for that resource, and 421 that any such mechanism can be mapped to a simple sequence of octets 422 for easy comparison. Since the value is opaque, there is no need for 423 the client to be aware of how each entity-tag is constructed. 425 For example, a resource that has implementation-specific versioning 426 applied to all changes might use an internal revision number, perhaps 427 combined with a variance identifier for content negotiation, to 428 accurately differentiate between representations. Other 429 implementations might use a collision-resistant hash of 430 representation content, a combination of various file attributes, or 431 a modification timestamp that has sub-second resolution. 433 An origin server SHOULD send an ETag for any selected representation 434 for which detection of changes can be reasonably and consistently 435 determined, since the entity-tag's use in conditional requests and 436 evaluating cache freshness ([CACHING]) can result in a substantial 437 reduction of HTTP network traffic and can be a significant factor in 438 improving service scalability and reliability. 440 2.3.2. Comparison 442 There are two entity-tag comparison functions, depending on whether 443 or not the comparison context allows the use of weak validators: 445 o Strong comparison: two entity-tags are equivalent if both are not 446 weak and their opaque-tags match character-by-character. 448 o Weak comparison: two entity-tags are equivalent if their opaque- 449 tags match character-by-character, regardless of either or both 450 being tagged as "weak". 452 The example below shows the results for a set of entity-tag pairs and 453 both the weak and strong comparison function results: 455 +--------+--------+-------------------+-----------------+ 456 | ETag 1 | ETag 2 | Strong Comparison | Weak Comparison | 457 +--------+--------+-------------------+-----------------+ 458 | W/"1" | W/"1" | no match | match | 459 | W/"1" | W/"2" | no match | no match | 460 | W/"1" | "1" | no match | match | 461 | "1" | "1" | match | match | 462 +--------+--------+-------------------+-----------------+ 464 2.3.3. Example: Entity-Tags Varying on Content-Negotiated Resources 466 Consider a resource that is subject to content negotiation 467 (Section 3.4 of [SEMNTCS]), and where the representations sent in 468 response to a GET request vary based on the Accept-Encoding request 469 header field (Section 5.3.4 of [SEMNTCS]): 471 >> Request: 473 GET /index HTTP/1.1 474 Host: www.example.com 475 Accept-Encoding: gzip 477 In this case, the response might or might not use the gzip content 478 coding. If it does not, the response might look like: 480 >> Response: 482 HTTP/1.1 200 OK 483 Date: Fri, 26 Mar 2010 00:05:00 GMT 484 ETag: "123-a" 485 Content-Length: 70 486 Vary: Accept-Encoding 487 Content-Type: text/plain 489 Hello World! 490 Hello World! 491 Hello World! 492 Hello World! 493 Hello World! 495 An alternative representation that does use gzip content coding would 496 be: 498 >> Response: 500 HTTP/1.1 200 OK 501 Date: Fri, 26 Mar 2010 00:05:00 GMT 502 ETag: "123-b" 503 Content-Length: 43 504 Vary: Accept-Encoding 505 Content-Type: text/plain 506 Content-Encoding: gzip 508 ...binary data... 510 Note: Content codings are a property of the representation data, 511 so a strong entity-tag for a content-encoded representation has to 512 be distinct from the entity tag of an unencoded representation to 513 prevent potential conflicts during cache updates and range 514 requests. In contrast, transfer codings (Section 4 of [MESSGNG]) 515 apply only during message transfer and do not result in distinct 516 entity-tags. 518 2.4. When to Use Entity-Tags and Last-Modified Dates 520 In 200 (OK) responses to GET or HEAD, an origin server: 522 o SHOULD send an entity-tag validator unless it is not feasible to 523 generate one. 525 o MAY send a weak entity-tag instead of a strong entity-tag, if 526 performance considerations support the use of weak entity-tags, or 527 if it is unfeasible to send a strong entity-tag. 529 o SHOULD send a Last-Modified value if it is feasible to send one. 531 In other words, the preferred behavior for an origin server is to 532 send both a strong entity-tag and a Last-Modified value in successful 533 responses to a retrieval request. 535 A client: 537 o MUST send that entity-tag in any cache validation request (using 538 If-Match or If-None-Match) if an entity-tag has been provided by 539 the origin server. 541 o SHOULD send the Last-Modified value in non-subrange cache 542 validation requests (using If-Modified-Since) if only a Last- 543 Modified value has been provided by the origin server. 545 o MAY send the Last-Modified value in subrange cache validation 546 requests (using If-Unmodified-Since) if only a Last-Modified value 547 has been provided by an HTTP/1.0 origin server. The user agent 548 SHOULD provide a way to disable this, in case of difficulty. 550 o SHOULD send both validators in cache validation requests if both 551 an entity-tag and a Last-Modified value have been provided by the 552 origin server. This allows both HTTP/1.0 and HTTP/1.1 caches to 553 respond appropriately. 555 3. Precondition Header Fields 557 This section defines the syntax and semantics of HTTP/1.1 header 558 fields for applying preconditions on requests. Section 5 defines 559 when the preconditions are applied. Section 6 defines the order of 560 evaluation when more than one precondition is present. 562 3.1. If-Match 564 The "If-Match" header field makes the request method conditional on 565 the recipient origin server either having at least one current 566 representation of the target resource, when the field-value is "*", 567 or having a current representation of the target resource that has an 568 entity-tag matching a member of the list of entity-tags provided in 569 the field-value. 571 An origin server MUST use the strong comparison function when 572 comparing entity-tags for If-Match (Section 2.3.2), since the client 573 intends this precondition to prevent the method from being applied if 574 there have been any changes to the representation data. 576 If-Match = "*" / 1#entity-tag 578 Examples: 580 If-Match: "xyzzy" 581 If-Match: "xyzzy", "r2d2xxxx", "c3piozzzz" 582 If-Match: * 584 If-Match is most often used with state-changing methods (e.g., POST, 585 PUT, DELETE) to prevent accidental overwrites when multiple user 586 agents might be acting in parallel on the same resource (i.e., to 587 prevent the "lost update" problem). It can also be used with safe 588 methods to abort a request if the selected representation does not 589 match one already stored (or partially stored) from a prior request. 591 An origin server that receives an If-Match header field MUST evaluate 592 the condition prior to performing the method (Section 5). If the 593 field-value is "*", the condition is false if the origin server does 594 not have a current representation for the target resource. If the 595 field-value is a list of entity-tags, the condition is false if none 596 of the listed tags match the entity-tag of the selected 597 representation. 599 An origin server MUST NOT perform the requested method if a received 600 If-Match condition evaluates to false; instead, the origin server 601 MUST respond with either a) the 412 (Precondition Failed) status code 602 or b) one of the 2xx (Successful) status codes if the origin server 603 has verified that a state change is being requested and the final 604 state is already reflected in the current state of the target 605 resource (i.e., the change requested by the user agent has already 606 succeeded, but the user agent might not be aware of it, perhaps 607 because the prior response was lost or a compatible change was made 608 by some other user agent). In the latter case, the origin server 609 MUST NOT send a validator header field in the response unless it can 610 verify that the request is a duplicate of an immediately prior change 611 made by the same user agent. 613 The If-Match header field can be ignored by caches and intermediaries 614 because it is not applicable to a stored response. 616 3.2. If-None-Match 618 The "If-None-Match" header field makes the request method conditional 619 on a recipient cache or origin server either not having any current 620 representation of the target resource, when the field-value is "*", 621 or having a selected representation with an entity-tag that does not 622 match any of those listed in the field-value. 624 A recipient MUST use the weak comparison function when comparing 625 entity-tags for If-None-Match (Section 2.3.2), since weak entity-tags 626 can be used for cache validation even if there have been changes to 627 the representation data. 629 If-None-Match = "*" / 1#entity-tag 631 Examples: 633 If-None-Match: "xyzzy" 634 If-None-Match: W/"xyzzy" 635 If-None-Match: "xyzzy", "r2d2xxxx", "c3piozzzz" 636 If-None-Match: W/"xyzzy", W/"r2d2xxxx", W/"c3piozzzz" 637 If-None-Match: * 639 If-None-Match is primarily used in conditional GET requests to enable 640 efficient updates of cached information with a minimum amount of 641 transaction overhead. When a client desires to update one or more 642 stored responses that have entity-tags, the client SHOULD generate an 643 If-None-Match header field containing a list of those entity-tags 644 when making a GET request; this allows recipient servers to send a 645 304 (Not Modified) response to indicate when one of those stored 646 responses matches the selected representation. 648 If-None-Match can also be used with a value of "*" to prevent an 649 unsafe request method (e.g., PUT) from inadvertently modifying an 650 existing representation of the target resource when the client 651 believes that the resource does not have a current representation 652 (Section 4.2.1 of [SEMNTCS]). This is a variation on the "lost 653 update" problem that might arise if more than one client attempts to 654 create an initial representation for the target resource. 656 An origin server that receives an If-None-Match header field MUST 657 evaluate the condition prior to performing the method (Section 5). 658 If the field-value is "*", the condition is false if the origin 659 server has a current representation for the target resource. If the 660 field-value is a list of entity-tags, the condition is false if one 661 of the listed tags match the entity-tag of the selected 662 representation. 664 An origin server MUST NOT perform the requested method if the 665 condition evaluates to false; instead, the origin server MUST respond 666 with either a) the 304 (Not Modified) status code if the request 667 method is GET or HEAD or b) the 412 (Precondition Failed) status code 668 for all other request methods. 670 Requirements on cache handling of a received If-None-Match header 671 field are defined in Section 4.3.2 of [CACHING]. 673 3.3. If-Modified-Since 675 The "If-Modified-Since" header field makes a GET or HEAD request 676 method conditional on the selected representation's modification date 677 being more recent than the date provided in the field-value. 678 Transfer of the selected representation's data is avoided if that 679 data has not changed. 681 If-Modified-Since = HTTP-date 683 An example of the field is: 685 If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT 687 A recipient MUST ignore If-Modified-Since if the request contains an 688 If-None-Match header field; the condition in If-None-Match is 689 considered to be a more accurate replacement for the condition in If- 690 Modified-Since, and the two are only combined for the sake of 691 interoperating with older intermediaries that might not implement If- 692 None-Match. 694 A recipient MUST ignore the If-Modified-Since header field if the 695 received field-value is not a valid HTTP-date, or if the request 696 method is neither GET nor HEAD. 698 A recipient MUST interpret an If-Modified-Since field-value's 699 timestamp in terms of the origin server's clock. 701 If-Modified-Since is typically used for two distinct purposes: 1) to 702 allow efficient updates of a cached representation that does not have 703 an entity-tag and 2) to limit the scope of a web traversal to 704 resources that have recently changed. 706 When used for cache updates, a cache will typically use the value of 707 the cached message's Last-Modified field to generate the field value 708 of If-Modified-Since. This behavior is most interoperable for cases 709 where clocks are poorly synchronized or when the server has chosen to 710 only honor exact timestamp matches (due to a problem with Last- 711 Modified dates that appear to go "back in time" when the origin 712 server's clock is corrected or a representation is restored from an 713 archived backup). However, caches occasionally generate the field 714 value based on other data, such as the Date header field of the 715 cached message or the local clock time that the message was received, 716 particularly when the cached message does not contain a Last-Modified 717 field. 719 When used for limiting the scope of retrieval to a recent time 720 window, a user agent will generate an If-Modified-Since field value 721 based on either its own local clock or a Date header field received 722 from the server in a prior response. Origin servers that choose an 723 exact timestamp match based on the selected representation's Last- 724 Modified field will not be able to help the user agent limit its data 725 transfers to only those changed during the specified window. 727 An origin server that receives an If-Modified-Since header field 728 SHOULD evaluate the condition prior to performing the method 729 (Section 5). The origin server SHOULD NOT perform the requested 730 method if the selected representation's last modification date is 731 earlier than or equal to the date provided in the field-value; 732 instead, the origin server SHOULD generate a 304 (Not Modified) 733 response, including only those metadata that are useful for 734 identifying or updating a previously cached response. 736 Requirements on cache handling of a received If-Modified-Since header 737 field are defined in Section 4.3.2 of [CACHING]. 739 3.4. If-Unmodified-Since 741 The "If-Unmodified-Since" header field makes the request method 742 conditional on the selected representation's last modification date 743 being earlier than or equal to the date provided in the field-value. 744 This field accomplishes the same purpose as If-Match for cases where 745 the user agent does not have an entity-tag for the representation. 747 If-Unmodified-Since = HTTP-date 749 An example of the field is: 751 If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT 753 A recipient MUST ignore If-Unmodified-Since if the request contains 754 an If-Match header field; the condition in If-Match is considered to 755 be a more accurate replacement for the condition in If-Unmodified- 756 Since, and the two are only combined for the sake of interoperating 757 with older intermediaries that might not implement If-Match. 759 A recipient MUST ignore the If-Unmodified-Since header field if the 760 received field-value is not a valid HTTP-date. 762 A recipient MUST interpret an If-Unmodified-Since field-value's 763 timestamp in terms of the origin server's clock. 765 If-Unmodified-Since is most often used with state-changing methods 766 (e.g., POST, PUT, DELETE) to prevent accidental overwrites when 767 multiple user agents might be acting in parallel on a resource that 768 does not supply entity-tags with its representations (i.e., to 769 prevent the "lost update" problem). It can also be used with safe 770 methods to abort a request if the selected representation does not 771 match one already stored (or partially stored) from a prior request. 773 An origin server that receives an If-Unmodified-Since header field 774 MUST evaluate the condition prior to performing the method 775 (Section 5). The origin server MUST NOT perform the requested method 776 if the selected representation's last modification date is more 777 recent than the date provided in the field-value; instead the origin 778 server MUST respond with either a) the 412 (Precondition Failed) 779 status code or b) one of the 2xx (Successful) status codes if the 780 origin server has verified that a state change is being requested and 781 the final state is already reflected in the current state of the 782 target resource (i.e., the change requested by the user agent has 783 already succeeded, but the user agent might not be aware of that 784 because the prior response message was lost or a compatible change 785 was made by some other user agent). In the latter case, the origin 786 server MUST NOT send a validator header field in the response unless 787 it can verify that the request is a duplicate of an immediately prior 788 change made by the same user agent. 790 The If-Unmodified-Since header field can be ignored by caches and 791 intermediaries because it is not applicable to a stored response. 793 3.5. If-Range 795 The "If-Range" header field provides a special conditional request 796 mechanism that is similar to the If-Match and If-Unmodified-Since 797 header fields but that instructs the recipient to ignore the Range 798 header field if the validator doesn't match, resulting in transfer of 799 the new selected representation instead of a 412 (Precondition 800 Failed) response. If-Range is defined in Section 3.2 of [RANGERQ]. 802 4. Status Code Definitions 804 4.1. 304 Not Modified 806 The 304 (Not Modified) status code indicates that a conditional GET 807 or HEAD request has been received and would have resulted in a 200 808 (OK) response if it were not for the fact that the condition 809 evaluated to false. In other words, there is no need for the server 810 to transfer a representation of the target resource because the 811 request indicates that the client, which made the request 812 conditional, already has a valid representation; the server is 813 therefore redirecting the client to make use of that stored 814 representation as if it were the payload of a 200 (OK) response. 816 The server generating a 304 response MUST generate any of the 817 following header fields that would have been sent in a 200 (OK) 818 response to the same request: Cache-Control, Content-Location, Date, 819 ETag, Expires, and Vary. 821 Since the goal of a 304 response is to minimize information transfer 822 when the recipient already has one or more cached representations, a 823 sender SHOULD NOT generate representation metadata other than the 824 above listed fields unless said metadata exists for the purpose of 825 guiding cache updates (e.g., Last-Modified might be useful if the 826 response does not have an ETag field). 828 Requirements on a cache that receives a 304 response are defined in 829 Section 4.3.4 of [CACHING]. If the conditional request originated 830 with an outbound client, such as a user agent with its own cache 831 sending a conditional GET to a shared proxy, then the proxy SHOULD 832 forward the 304 response to that client. 834 A 304 response cannot contain a message-body; it is always terminated 835 by the first empty line after the header fields. 837 4.2. 412 Precondition Failed 839 The 412 (Precondition Failed) status code indicates that one or more 840 conditions given in the request header fields evaluated to false when 841 tested on the server. This response code allows the client to place 842 preconditions on the current resource state (its current 843 representations and metadata) and, thus, prevent the request method 844 from being applied if the target resource is in an unexpected state. 846 5. Evaluation 848 Except when excluded below, a recipient cache or origin server MUST 849 evaluate received request preconditions after it has successfully 850 performed its normal request checks and just before it would perform 851 the action associated with the request method. A server MUST ignore 852 all received preconditions if its response to the same request 853 without those conditions would have been a status code other than a 854 2xx (Successful) or 412 (Precondition Failed). In other words, 855 redirects and failures take precedence over the evaluation of 856 preconditions in conditional requests. 858 A server that is not the origin server for the target resource and 859 cannot act as a cache for requests on the target resource MUST NOT 860 evaluate the conditional request header fields defined by this 861 specification, and it MUST forward them if the request is forwarded, 862 since the generating client intends that they be evaluated by a 863 server that can provide a current representation. Likewise, a server 864 MUST ignore the conditional request header fields defined by this 865 specification when received with a request method that does not 866 involve the selection or modification of a selected representation, 867 such as CONNECT, OPTIONS, or TRACE. 869 Conditional request header fields that are defined by extensions to 870 HTTP might place conditions on all recipients, on the state of the 871 target resource in general, or on a group of resources. For 872 instance, the "If" header field in WebDAV can make a request 873 conditional on various aspects of multiple resources, such as locks, 874 if the recipient understands and implements that field ([RFC4918], 875 Section 10.4). 877 Although conditional request header fields are defined as being 878 usable with the HEAD method (to keep HEAD's semantics consistent with 879 those of GET), there is no point in sending a conditional HEAD 880 because a successful response is around the same size as a 304 (Not 881 Modified) response and more useful than a 412 (Precondition Failed) 882 response. 884 6. Precedence 886 When more than one conditional request header field is present in a 887 request, the order in which the fields are evaluated becomes 888 important. In practice, the fields defined in this document are 889 consistently implemented in a single, logical order, since "lost 890 update" preconditions have more strict requirements than cache 891 validation, a validated cache is more efficient than a partial 892 response, and entity tags are presumed to be more accurate than date 893 validators. 895 A recipient cache or origin server MUST evaluate the request 896 preconditions defined by this specification in the following order: 898 1. When recipient is the origin server and If-Match is present, 899 evaluate the If-Match precondition: 901 * if true, continue to step 3 903 * if false, respond 412 (Precondition Failed) unless it can be 904 determined that the state-changing request has already 905 succeeded (see Section 3.1) 907 2. When recipient is the origin server, If-Match is not present, and 908 If-Unmodified-Since is present, evaluate the If-Unmodified-Since 909 precondition: 911 * if true, continue to step 3 912 * if false, respond 412 (Precondition Failed) unless it can be 913 determined that the state-changing request has already 914 succeeded (see Section 3.4) 916 3. When If-None-Match is present, evaluate the If-None-Match 917 precondition: 919 * if true, continue to step 5 921 * if false for GET/HEAD, respond 304 (Not Modified) 923 * if false for other methods, respond 412 (Precondition Failed) 925 4. When the method is GET or HEAD, If-None-Match is not present, and 926 If-Modified-Since is present, evaluate the If-Modified-Since 927 precondition: 929 * if true, continue to step 5 931 * if false, respond 304 (Not Modified) 933 5. When the method is GET and both Range and If-Range are present, 934 evaluate the If-Range precondition: 936 * if the validator matches and the Range specification is 937 applicable to the selected representation, respond 206 938 (Partial Content) [RANGERQ] 940 6. Otherwise, 942 * all conditions are met, so perform the requested action and 943 respond according to its success or failure. 945 Any extension to HTTP/1.1 that defines additional conditional request 946 header fields ought to define its own expectations regarding the 947 order for evaluating such fields in relation to those defined in this 948 document and other conditionals that might be found in practice. 950 7. IANA Considerations 952 7.1. Status Code Registration 954 The "Hypertext Transfer Protocol (HTTP) Status Code Registry" located 955 at has been 956 updated with the registrations below: 958 +-------+---------------------+--------------+ 959 | Value | Description | Reference | 960 +-------+---------------------+--------------+ 961 | 304 | Not Modified | Section 4.1 | 962 | 412 | Precondition Failed | Section 4.2 | 963 +-------+---------------------+--------------+ 965 7.2. Header Field Registration 967 HTTP header fields are registered within the "Message Headers" 968 registry maintained at . 971 This document defines the following HTTP header fields, so their 972 associated registry entries have been updated according to the 973 permanent registrations below (see [BCP90]): 975 +---------------------+----------+----------+--------------+ 976 | Header Field Name | Protocol | Status | Reference | 977 +---------------------+----------+----------+--------------+ 978 | ETag | http | standard | Section 2.3 | 979 | If-Match | http | standard | Section 3.1 | 980 | If-Modified-Since | http | standard | Section 3.3 | 981 | If-None-Match | http | standard | Section 3.2 | 982 | If-Unmodified-Since | http | standard | Section 3.4 | 983 | Last-Modified | http | standard | Section 2.2 | 984 +---------------------+----------+----------+--------------+ 986 The change controller is: "IETF (iesg@ietf.org) - Internet 987 Engineering Task Force". 989 8. Security Considerations 991 This section is meant to inform developers, information providers, 992 and users of known security concerns specific to the HTTP conditional 993 request mechanisms. More general security considerations are 994 addressed in HTTP "Message Syntax and Routing" [MESSGNG] and 995 "Semantics and Content" [SEMNTCS]. 997 The validators defined by this specification are not intended to 998 ensure the validity of a representation, guard against malicious 999 changes, or detect man-in-the-middle attacks. At best, they enable 1000 more efficient cache updates and optimistic concurrent writes when 1001 all participants are behaving nicely. At worst, the conditions will 1002 fail and the client will receive a response that is no more harmful 1003 than an HTTP exchange without conditional requests. 1005 An entity-tag can be abused in ways that create privacy risks. For 1006 example, a site might deliberately construct a semantically invalid 1007 entity-tag that is unique to the user or user agent, send it in a 1008 cacheable response with a long freshness time, and then read that 1009 entity-tag in later conditional requests as a means of re-identifying 1010 that user or user agent. Such an identifying tag would become a 1011 persistent identifier for as long as the user agent retained the 1012 original cache entry. User agents that cache representations ought 1013 to ensure that the cache is cleared or replaced whenever the user 1014 performs privacy-maintaining actions, such as clearing stored cookies 1015 or changing to a private browsing mode. 1017 9. References 1019 9.1. Normative References 1021 [CACHING] Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, 1022 Ed., "Hypertext Transfer Protocol (HTTP): Caching", draft- 1023 fielding-httpbis-http-cache-00 (work in progress), March 1024 2018. 1026 [MESSGNG] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer 1027 Protocol (HTTP/1.1): Message Syntax and Routing", draft- 1028 fielding-httpbis-http-messaging-00 (work in progress), 1029 March 2018. 1031 [RANGERQ] Fielding, R., Ed., Lafon, Y., Ed., and J. Reschke, Ed., 1032 "Hypertext Transfer Protocol (HTTP): Range Requests", 1033 draft-fielding-httpbis-http-range-00 (work in progress), 1034 March 2018. 1036 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1037 Requirement Levels", BCP 14, RFC 2119, 1038 DOI 10.17487/RFC2119, March 1997, 1039 . 1041 [RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax 1042 Specifications: ABNF", STD 68, RFC 5234, 1043 DOI 10.17487/RFC5234, January 2008, 1044 . 1046 [SEMNTCS] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer 1047 Protocol (HTTP): Semantics and Content", draft-fielding- 1048 httpbis-http-semantics-00 (work in progress), March 2018. 1050 9.2. Informative References 1052 [BCP90] Klyne, G., Nottingham, M., and J. Mogul, "Registration 1053 Procedures for Message Header Fields", BCP 90, RFC 3864, 1054 September 2004, . 1056 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 1057 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 1058 Transfer Protocol -- HTTP/1.1", RFC 2616, 1059 DOI 10.17487/RFC2616, June 1999, 1060 . 1062 [RFC4918] Dusseault, L., Ed., "HTTP Extensions for Web Distributed 1063 Authoring and Versioning (WebDAV)", RFC 4918, 1064 DOI 10.17487/RFC4918, June 2007, 1065 . 1067 [RFC7232] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer 1068 Protocol (HTTP/1.1): Conditional Requests", RFC 7232, 1069 DOI 10.17487/RFC7232, June 2014, 1070 . 1072 Appendix A. Changes from RFC 7232 1074 None yet. 1076 Appendix B. Imported ABNF 1078 The following core rules are included by reference, as defined in 1079 Appendix B.1 of [RFC5234]: ALPHA (letters), CR (carriage return), 1080 CRLF (CR LF), CTL (controls), DIGIT (decimal 0-9), DQUOTE (double 1081 quote), HEXDIG (hexadecimal 0-9/A-F/a-f), LF (line feed), OCTET (any 1082 8-bit sequence of data), SP (space), and VCHAR (any visible US-ASCII 1083 character). 1085 The rules below are defined in [MESSGNG]: 1087 OWS = 1088 obs-text = 1090 The rules below are defined in other parts: 1092 HTTP-date = 1094 Appendix C. Collected ABNF 1096 In the collected ABNF below, list rules are expanded as per 1097 Section 1.2 of [MESSGNG]. 1099 ETag = entity-tag 1101 HTTP-date = 1103 If-Match = "*" / ( *( "," OWS ) entity-tag *( OWS "," [ OWS 1104 entity-tag ] ) ) 1105 If-Modified-Since = HTTP-date 1106 If-None-Match = "*" / ( *( "," OWS ) entity-tag *( OWS "," [ OWS 1107 entity-tag ] ) ) 1108 If-Unmodified-Since = HTTP-date 1110 Last-Modified = HTTP-date 1112 OWS = 1114 entity-tag = [ weak ] opaque-tag 1115 etagc = "!" / %x23-7E ; '#'-'~' 1116 / obs-text 1118 obs-text = 1119 opaque-tag = DQUOTE *etagc DQUOTE 1121 weak = %x57.2F ; W/ 1123 Appendix D. Change Log 1125 This section is to be removed before publishing as an RFC. 1127 D.1. Since RFC 7232 1129 The changes in this draft are purely editorial: 1131 o Change boilerplate and abstract to indicate the "draft" status, 1132 and update references to ancestor specifications. 1134 o Remove version "1.1" from document title, indicating that this 1135 specification applies to all HTTP versions. 1137 o Adjust historical notes. 1139 o Update links to sibling specifications. 1141 o Replace sections listing changes from RFC 2616 by new empty 1142 sections referring to RFC 723x. 1144 o Remove acknowledgements specific to RFC 723x. 1146 o Move "Acknowledgements" to the very end and make them unnumbered. 1148 Index 1150 3 1151 304 Not Modified (status code) 17 1153 4 1154 412 Precondition Failed (status code) 18 1156 E 1157 ETag header field 8 1159 G 1160 Grammar 1161 entity-tag 9 1162 ETag 9 1163 etagc 9 1164 If-Match 12 1165 If-Modified-Since 15 1166 If-None-Match 14 1167 If-Unmodified-Since 16 1168 Last-Modified 6 1169 opaque-tag 9 1170 weak 9 1172 I 1173 If-Match header field 12 1174 If-Modified-Since header field 15 1175 If-None-Match header field 13 1176 If-Unmodified-Since header field 16 1178 L 1179 Last-Modified header field 6 1181 M 1182 metadata 4 1184 S 1185 selected representation 4 1187 V 1188 validator 4 1189 strong 5 1190 weak 5 1192 Acknowledgments 1194 See Appendix "Acknowledgments" of [MESSGNG]. 1196 Authors' Addresses 1198 Roy T. Fielding (editor) 1199 Adobe Systems Incorporated 1200 345 Park Ave 1201 San Jose, CA 95110 1202 USA 1204 EMail: fielding@gbiv.com 1205 URI: http://roy.gbiv.com/ 1207 Julian F. Reschke (editor) 1208 greenbytes GmbH 1209 Hafenweg 16 1210 Muenster, NW 48155 1211 Germany 1213 EMail: julian.reschke@greenbytes.de 1214 URI: http://greenbytes.de/tech/webdav/