|HTTPbis Working Group||R. Fielding, Editor|
|Obsoletes: 2616 (if approved)||J. Gettys|
|Intended status: Standards Track||Alcatel-Lucent|
|Expires: October 1, 2011||J. Mogul|
|Y. Lafon, Editor|
|J. Reschke, Editor|
|March 30, 2011|
HTTP/1.1, part 4: Conditional Requests
The Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems. HTTP has been in use by the World Wide Web global information initiative since 1990. This document is Part 4 of the seven-part specification that defines the protocol referred to as "HTTP/1.1" and, taken together, obsoletes RFC 2616. Part 4 defines request header fields for indicating conditional requests and the rules for constructing responses to those requests.
Discussion of this draft should take place on the HTTPBIS working group mailing list (firstname.lastname@example.org). The current issues list is at <http://tools.ietf.org/wg/httpbis/trac/report/3> and related documents (including fancy diffs) can be found at <http://tools.ietf.org/wg/httpbis/>.
The changes in this draft are summarized in Appendix C.15.
This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.
Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at http://datatracker.ietf.org/drafts/current/.
Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as “work in progress”.
This Internet-Draft will expire on October 1, 2011.
Copyright © 2011 IETF Trust and the persons identified as the document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.
This document may contain material from IETF Documents or IETF Contributions published or made publicly available before November 10, 2008. The person(s) controlling the copyright in some of this material may not have granted the IETF Trust the right to allow modifications of such material outside the IETF Standards Process. Without obtaining an adequate license from the person(s) controlling the copyright in such materials, this document may not be modified outside the IETF Standards Process, and derivative works of it may not be created outside the IETF Standards Process, except to format it for publication as an RFC or to translate it into languages other than English.
This document defines HTTP/1.1 response metadata for indicating potential changes to payload content, including modification time stamps and opaque entity-tags, and the HTTP conditional request mechanisms that allow preconditions to be placed on a request method. Conditional GET requests allow for efficient cache updates. Other conditional request methods are used to protect against overwriting or misunderstanding the state of a resource that has been changed unbeknownst to the requesting client.
We use the term "selected representation" to refer to the current representation of the target resource that would have been selected and sent as payload in a 200 (OK) response if the same request had used the method GET and had excluded all of the conditional request header fields. The conditions found within conditional requests are evaluated on the basis of either the state of the target resource as a whole or the state of the target resource's selected representation.
This document is currently disorganized in order to minimize the changes between drafts and enable reviewers to see the smaller errata changes. A future draft will reorganize the sections to better reflect the content. In particular, the sections on resource metadata will be discussed first and then followed by each conditional request header field, concluding with a definition of precedence and the expectation of ordering strong validator checks before weak validator checks. It is likely that more content from [Part6] will migrate to this part, where appropriate. The current mess reflects how widely dispersed these topics and associated requirements had become in [RFC2616].
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC2119].
An implementation is not compliant if it fails to satisfy one or more of the "MUST" or "REQUIRED" level requirements for the protocols it implements. An implementation that satisfies all the "MUST" or "REQUIRED" level and all the "SHOULD" level requirements for its protocols is said to be "unconditionally compliant"; one that satisfies all the "MUST" level requirements but not all the "SHOULD" level requirements for its protocols is said to be "conditionally compliant".
This specification uses the ABNF syntax defined in Section 1.2 of [Part1] (which extends the syntax defined in [RFC5234] with a list rule). Appendix B shows the collected ABNF, with the list rule expanded.
The following core rules are included by reference, as defined in [RFC5234], Appendix B.1: ALPHA (letters), CR (carriage return), CRLF (CR LF), CTL (controls), DIGIT (decimal 0-9), DQUOTE (double quote), HEXDIG (hexadecimal 0-9/A-F/a-f), LF (line feed), OCTET (any 8-bit sequence of data), SP (space), VCHAR (any visible USASCII character), and WSP (whitespace).
The core rules below are defined in Section 1.2.2 of [Part1]:
quoted-string = <quoted-string, defined in [Part1], Section 1.2.2> OWS = <OWS, defined in [Part1], Section 1.2.2>
The ABNF rules below are defined in other parts:
HTTP-date = <HTTP-date, defined in [Part1], Section 6.1>
Entity-tags are used for comparing two or more representations of the same resource. HTTP/1.1 uses entity-tags in the ETag (Section 6.1), If-Match (Section 6.2), If-None-Match (Section 6.4), and If-Range (Section 5.3 of [Part5]) header fields. The definition of how they are used and compared as cache validators is in Section 4. An entity-tag consists of an opaque quoted string, possibly prefixed by a weakness indicator.
entity-tag = [ weak ] opaque-tag weak = %x57.2F ; "W/", case-sensitive opaque-tag = quoted-string
A "strong entity-tag" MAY be shared by two representations of a resource only if they are equivalent by octet equality.
A "weak entity-tag", indicated by the "W/" prefix, MAY be shared by two representations of a resource. A weak entity-tag can only be used for weak comparison.
Cache entries might persist for arbitrarily long periods, regardless of expiration times, so it is inappropriate to expect that a cache will never again attempt to validate an entry using a validator that it obtained at some point in the past. A strong entity-tag MUST be unique across all versions of all representations associated with a particular resource over time. However, there is no implication of uniqueness across entity-tags of different resources (i.e., the same entity-tag value might be in use for representations of multiple resources at the same time and does not imply that those representations are equivalent).
Consider a resource that is subject to content negotiation (Section 5 of [Part3]), and where the representations returned upon a GET request vary based on the Accept-Encoding request header field (Section 6.3 of [Part3]):
GET /index HTTP/1.1 Host: www.example.com Accept-Encoding: gzip
In this case, the response might or might not use the gzip content coding. If it does not, the response might look like:
HTTP/1.1 200 OK Date: Thu, 26 Mar 2010 00:05:00 GMT ETag: "123-a" Content-Length: 70 Vary: Accept-Encoding Content-Type: text/plain Hello World! Hello World! Hello World! Hello World! Hello World!
An alternative representation that does use gzip content coding would be:
HTTP/1.1 200 OK Date: Thu, 26 Mar 2010 00:05:00 GMT ETag: "123-b" Content-Length: 43 Vary: Accept-Encoding Content-Type: text/plain Content-Encoding: gzip ...binary data...
Note: Content codings are a property of the representation, so therefore an entity-tag of an encoded representation must be distinct from an unencoded representation to prevent conflicts during cache updates and range requests. In contrast, transfer codings (Section 6.2 of [Part1]) apply only during message transfer and do not require distinct entity-tags.
The 304 status code indicates that a conditional GET request has been received and would have resulted in a 200 (OK) response if it were not for the fact that the condition has evaluated to false. In other words, there is no need for the server to transfer a representation of the target resource because the client's request indicates that it already has a valid representation, as indicated by the 304 response header fields, and is therefore redirecting the client to make use of that stored representation as if it were the payload of a 200 response. The 304 response MUST NOT contain a message-body, and thus is always terminated by the first empty line after the header fields.
A 304 response MUST include a Date header field (Section 9.3 of [Part1]) unless its omission is required by Section 9.3.1 of [Part1]. If a 200 response to the same request would have included any of the header fields Cache-Control, Content-Location, ETag, Expires, Last-Modified, or Vary, then those same header fields MUST be sent in a 304 response.
Since the goal of a 304 response is to minimize information transfer when the recipient already has one or more cached representations, the response SHOULD NOT include representation metadata other than the above listed fields unless said metadata exists for the purpose of guiding cache updates (e.g., future HTTP extensions).
If the recipient of a 304 response does not have a cached representation corresponding to the entity-tag indicated by the 304 response, then the recipient MUST NOT use the 304 to update its own cache. If this conditional request originated with an outbound client, such as a user agent with its own cache sending a conditional GET to a shared proxy, then the 304 response MAY be forwarded to the outbound client. Otherwise, the recipient MUST disregard the 304 response and repeat the request without any preconditions.
If a cache uses a received 304 response to update a cache entry, the cache MUST update the entry to reflect any new field values given in the response.
The 412 status code indicates that one or more preconditions given in the request header fields evaluated to false when tested on the server. This response code allows the client to place preconditions on the current resource state (its current representations and metadata) and thus prevent the request method from being applied if the target resource is in an unexpected state.
Since both origin servers and caches will compare two validators to decide if they represent the same or different representations, one normally would expect that if the representation (including both representation header fields and representation body) changes in any way, then the associated validator would change as well. If this is true, then we call this validator a "strong validator". One example of a strong validator is an integer that is incremented in stable storage every time a representation is changed.
However, there might be cases when a server prefers to change the validator only when it desires cached representations to be invalidated. For example, the representation of a weather report that changes in content every second, based on dynamic measurements, might be grouped into sets of equivalent representations (from the origin server's perspective) in order to allow cached representations to be valid for a reasonable period of time (perhaps adjusted dynamically based on server load or weather quality). A validator that does not always change when the representation changes is a "weak validator".
An entity-tag is normally a strong validator, but the protocol provides a mechanism to tag an entity-tag as "weak". One can think of a strong validator as part of an identifier for a specific representation, whereas a weak validator is part of an identifier for a set of equivalent representations (where this notion of equivalence is entirely governed by the origin server and beyond the scope of this specification).
A strong entity-tag MUST change whenever the associated representation changes in any way. A weak entity-tag SHOULD change whenever the origin server considers prior representations to be unacceptable as a substitute for the current representation. In other words, a weak entity tag SHOULD change whenever the origin server wants caches to invalidate old responses.
A "use" of a validator is either when a client generates a request and includes the validator in a validating header field, or when a server compares two validators.
Strong validators are usable in any context. Weak validators are only usable in contexts that do not depend on exact equality of a representation. For example, either kind is usable for a normal conditional GET. However, only a strong validator is usable for range retrieval ([Part5]), since otherwise the client might end up with an internally inconsistent representation. Clients MUST NOT use weak validators in range requests.
The only function that HTTP/1.1 defines on validators is comparison. There are two validator comparison functions, depending on whether the comparison context allows the use of weak validators or not:
The example below shows the results for a set of entity-tag pairs, and both the weak and strong comparison function results:
|ETag 1||ETag 2||Strong Comparison||Weak Comparison|
|W/"1"||W/"2"||no match||no match|
An entity-tag is strong unless it is explicitly tagged as weak. Section 2 gives the syntax for entity-tags.
A Last-Modified time, when used as a validator in a request, is implicitly weak unless it is possible to deduce that it is strong, using the following rules:
This method relies on the fact that if two different responses were sent by the origin server during the same second, but both had the same Last-Modified time, then at least one of those responses would have a Date value equal to its Last-Modified time. The arbitrary 60-second limit guards against the possibility that the Date and Last-Modified values are generated from different clocks, or at somewhat different times during the preparation of the response. An implementation MAY use a value larger than 60 seconds, if it is believed that 60 seconds is too short.
If a client wishes to perform a sub-range retrieval on a value for which it has only a Last-Modified time and no opaque validator, it MAY do this only if the Last-Modified time is strong in the sense described here.
A cache or origin server receiving a conditional range request ([Part5]) MUST use the strong comparison function to evaluate the condition.
These rules allow HTTP/1.1 caches and clients to safely perform sub-range retrievals on values that have been obtained from HTTP/1.0 servers.
We adopt a set of rules and recommendations for origin servers, clients, and caches regarding when various validator types ought to be used, and for what purposes.
HTTP/1.1 origin servers:
In other words, the preferred behavior for an HTTP/1.1 origin server is to send both a strong entity-tag and a Last-Modified value.
An HTTP/1.1 origin server, upon receiving a conditional request that includes both a Last-Modified date (e.g., in an If-Modified-Since or If-Unmodified-Since header field) and one or more entity-tags (e.g., in an If-Match, If-None-Match, or If-Range header field) as cache validators, MUST NOT return a response status code of 304 (Not Modified) unless doing so is consistent with all of the conditional header fields in the request.
An HTTP/1.1 caching proxy, upon receiving a conditional request that includes both a Last-Modified date and one or more entity-tags as cache validators, MUST NOT return a locally cached response to the client unless that cached response is consistent with all of the conditional header fields in the request.
This section defines the syntax and semantics of HTTP/1.1 header fields related to conditional requests.
The "ETag" header field provides the current value of the entity-tag (see Section 2) for one representation of the target resource. An entity-tag is intended for use as a resource-local identifier for differentiating between representations of the same resource that vary over time or via content negotiation (see Section 4).
ETag = entity-tag
ETag: "xyzzy" ETag: W/"xyzzy" ETag: ""
An entity-tag provides an "opaque" cache validator that allows for more reliable validation than modification dates in situations where it is inconvenient to store modification dates, where the one-second resolution of HTTP date values is not sufficient, or where the origin server wishes to avoid certain paradoxes that might arise from the use of modification dates.
The principle behind entity-tags is that only the service author knows the semantics of a resource well enough to select an appropriate cache validation mechanism, and the specification of any validator comparison function more complex than byte-equality would open up a can of worms. Thus, comparisons of any other header fields (except Last-Modified, for compatibility with HTTP/1.0) are never used for purposes of validating a cache entry.
The "If-Match" header field MAY be used to make a request method conditional on the current existence or value of an entity-tag for one or more representations of the target resource. If-Match is generally useful for resource update requests, such as PUT requests, as a means for protecting against accidental overwrites when multiple clients are acting in parallel on the same resource (i.e., the "lost update" problem). An If-Match field-value of "*" places the precondition on the existence of any current representation for the target resource.
If-Match = "*" / 1#entity-tag
If any of the entity-tags listed in the If-Match field value match the entity-tag of the selected representation for the target resource, or if "*" is given and any current representation exists for the target resource, then the server MAY perform the request method as if the If-Match header field was not present.
If none of the entity-tags match, or if "*" is given and no current representation exists, the server MUST NOT perform the requested method. Instead, the server MUST respond with the 412 (Precondition Failed) status code.
If the request would, without the If-Match header field, result in anything other than a 2xx or 412 status code, then the If-Match header field MUST be ignored.
If-Match: "xyzzy" If-Match: "xyzzy", "r2d2xxxx", "c3piozzzz" If-Match: *
The result of a request having both an If-Match header field and either an If-None-Match or an If-Modified-Since header fields is undefined by this specification.
The "If-Modified-Since" header field MAY be used to make a request method conditional by modification date: if the selected representation has not been modified since the time specified in this field, then do not perform the request method; instead, respond as detailed below.
If-Modified-Since = HTTP-date
An example of the field is:
If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT
A GET method with an If-Modified-Since header field and no Range header field requests that the selected representation be transferred only if it has been modified since the date given by the If-Modified-Since header field. The algorithm for determining this includes the following cases:
The purpose of this feature is to allow efficient updates of cached information with a minimum amount of transaction overhead.
The result of a request having both an If-Modified-Since header field and either an If-Match or an If-Unmodified-Since header fields is undefined by this specification.
The "If-None-Match" header field MAY be used to make a request method conditional on not matching any of the current entity-tag values for representations of the target resource. If-None-Match is primarily used in conditional GET requests to enable efficient updates of cached information with a minimum amount of transaction overhead. A client that has one or more representations previously obtained from the target resource can send If-None-Match with a list of the associated entity-tags in the hope of receiving a 304 response if at least one of those representations matches the selected representation.
If-None-Match MAY also be used with a value of "*" to prevent an unsafe request method (e.g., PUT) from inadvertently modifying an existing representation of the target resource when the client believes that the resource does not have a current representation. This is a variation on the "lost update" problem that might arise if more than one client attempts to create an initial representation for the target resource.
If-None-Match = "*" / 1#entity-tag
If any of the entity-tags listed in the If-None-Match field-value match the entity-tag of the selected representation, or if "*" is given and any current representation exists for that resource, then the server MUST NOT perform the requested method. Instead, if the request method was GET or HEAD, the server SHOULD respond with a 304 (Not Modified) status code, including the cache-related header fields (particularly ETag) of the selected representation that has a matching entity-tag. For all other request methods, the server MUST respond with a 412 (Precondition Failed) status code.
If none of the entity-tags match, then the server MAY perform the requested method as if the If-None-Match header field did not exist, but MUST also ignore any If-Modified-Since header field(s) in the request. That is, if no entity-tags match, then the server MUST NOT return a 304 (Not Modified) response.
If the request would, without the If-None-Match header field, result in anything other than a 2xx or 304 status code, then the If-None-Match header field MUST be ignored. (See Section 5 for a discussion of server behavior when both If-Modified-Since and If-None-Match appear in the same request.)
If-None-Match: "xyzzy" If-None-Match: W/"xyzzy" If-None-Match: "xyzzy", "r2d2xxxx", "c3piozzzz" If-None-Match: W/"xyzzy", W/"r2d2xxxx", W/"c3piozzzz" If-None-Match: *
The result of a request having both an If-None-Match header field and either an If-Match or an If-Unmodified-Since header fields is undefined by this specification.
The "If-Unmodified-Since" header field MAY be used to make a request method conditional by modification date: if the selected representation has been modified since the time specified in this field, then the server MUST NOT perform the requested operation and MUST instead respond with the 412 (Precondition Failed) status code. If the selected representation has not been modified since the time specified in this field, the server SHOULD perform the request method as if the If-Unmodified-Since header field were not present.
If-Unmodified-Since = HTTP-date
An example of the field is:
If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT
If the request normally (i.e., without the If-Unmodified-Since header field) would result in anything other than a 2xx or 412 status code, the If-Unmodified-Since header field SHOULD be ignored.
If the specified date is invalid, the header field MUST be ignored.
The result of a request having both an If-Unmodified-Since header field and either an If-None-Match or an If-Modified-Since header fields is undefined by this specification.
The "Last-Modified" header field indicates the date and time at which the origin server believes the representation was last modified.
Last-Modified = HTTP-date
An example of its use is
Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT
A representation is typically the sum of many parts behind the resource interface. The last-modified time would usually be the most recent time that any of those parts were changed. How that value is determined for any given resource is an implementation detail beyond the scope of this specification. What matters to HTTP is how recipients of the Last-Modified header field can use its value to make conditional requests and test the validity of locally cached responses.
An origin server MUST NOT send a Last-Modified date which is later than the server's time of message origination. In such cases, where the resource's last modification would indicate some time in the future, the server MUST replace that date with the message origination date.
An origin server SHOULD obtain the Last-Modified value of the representation as close as possible to the time that it generates the Date value of its response. This allows a recipient to make an accurate assessment of the representation's modification time, especially if the representation changes near the time that the response is generated.
HTTP/1.1 servers SHOULD send Last-Modified whenever feasible.
The Last-Modified header field value is often used as a cache validator. In simple terms, a cache entry is considered to be valid if the representation has not been modified since the Last-Modified value.
The HTTP Status Code Registry located at <http://www.iana.org/assignments/http-status-codes> shall be updated with the registrations below:
The Message Header Field Registry located at <http://www.iana.org/assignments/message-headers/message-header-index.html> shall be updated with the permanent registrations below (see [RFC3864]):
|Header Field Name||Protocol||Status||Reference|
The change controller is: "IETF (email@example.com) - Internet Engineering Task Force".
No additional security considerations have been identified beyond those applicable to HTTP in general [Part1].
|[Part1]||Fielding, R., Ed., Gettys, J., Mogul, J., Frystyk, H., Masinter, L., Leach, P., Berners-Lee, T., Lafon, Y., Ed., and J. Reschke, Ed., “HTTP/1.1, part 1: URIs, Connections, and Message Parsing”, Internet-Draft draft-ietf-httpbis-p1-messaging-latest (work in progress), March 2011.|
|[Part3]||Fielding, R., Ed., Gettys, J., Mogul, J., Frystyk, H., Masinter, L., Leach, P., Berners-Lee, T., Lafon, Y., Ed., and J. Reschke, Ed., “HTTP/1.1, part 3: Message Payload and Content Negotiation”, Internet-Draft draft-ietf-httpbis-p3-payload-latest (work in progress), March 2011.|
|[Part5]||Fielding, R., Ed., Gettys, J., Mogul, J., Frystyk, H., Masinter, L., Leach, P., Berners-Lee, T., Lafon, Y., Ed., and J. Reschke, Ed., “HTTP/1.1, part 5: Range Requests and Partial Responses”, Internet-Draft draft-ietf-httpbis-p5-range-latest (work in progress), March 2011.|
|[Part6]||Fielding, R., Ed., Gettys, J., Mogul, J., Frystyk, H., Masinter, L., Leach, P., Berners-Lee, T., Lafon, Y., Ed., Nottingham, M., Ed., and J. Reschke, Ed., “HTTP/1.1, part 6: Caching”, Internet-Draft draft-ietf-httpbis-p6-cache-latest (work in progress), March 2011.|
|[RFC2119]||Bradner, S., “Key words for use in RFCs to Indicate Requirement Levels”, BCP 14, RFC 2119, March 1997.|
|[RFC5234]||Crocker, D., Ed. and P. Overell, “Augmented BNF for Syntax Specifications: ABNF”, STD 68, RFC 5234, January 2008.|
|[RFC2616]||Fielding, R., Gettys, J., Mogul, J., Frystyk, H., Masinter, L., Leach, P., and T. Berners-Lee, “Hypertext Transfer Protocol -- HTTP/1.1”, RFC 2616, June 1999.|
|[RFC3864]||Klyne, G., Nottingham, M., and J. Mogul, “Registration Procedures for Message Header Fields”, BCP 90, RFC 3864, September 2004.|
Allow weak entity-tags in all requests except range requests (Sections 4 and 6.4).
Change ABNF productions for header fields to only define the field value. (Section 6)
ETag = entity-tag HTTP-date = <HTTP-date, defined in [Part1], Section 6.1> If-Match = "*" / ( *( "," OWS ) entity-tag *( OWS "," [ OWS entity-tag ] ) ) If-Modified-Since = HTTP-date If-None-Match = "*" / ( *( "," OWS ) entity-tag *( OWS "," [ OWS entity-tag ] ) ) If-Unmodified-Since = HTTP-date Last-Modified = HTTP-date OWS = <OWS, defined in [Part1], Section 1.2.2> entity-tag = [ weak ] opaque-tag opaque-tag = quoted-string quoted-string = <quoted-string, defined in [Part1], Section 1.2.2> weak = %x57.2F ; W/
; ETag defined but not used ; If-Match defined but not used ; If-Modified-Since defined but not used ; If-None-Match defined but not used ; If-Unmodified-Since defined but not used ; Last-Modified defined but not used
Extracted relevant partitions from [RFC2616].
Ongoing work on ABNF conversion (<http://tools.ietf.org/wg/httpbis/trac/ticket/36>):
Ongoing work on IANA Message Header Field Registration (<http://tools.ietf.org/wg/httpbis/trac/ticket/40>):
Ongoing work on ABNF conversion (<http://tools.ietf.org/wg/httpbis/trac/ticket/36>):
Final work on ABNF conversion (<http://tools.ietf.org/wg/httpbis/trac/ticket/36>):
No significant changes.
No significant changes.