Individual Submission | L. Dusseault |
Internet-Draft | OSAF |
Intended status: Informational | July 15, 2004 |
Expires: January 16, 2005 |
This document is an Internet-Draft and is in full conformance with all provisions of Section 10 of RFC2026.¶
Internet-Drafts are working documents of the Internet Engineering Task Force (IETF), its areas, and its working groups. Note that other groups may also distribute working documents as Internet-Drafts.¶
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”.¶
The list of current Internet-Drafts can be accessed at http://www.ietf.org/ietf/1id-abstracts.txt.¶
The list of Internet-Draft Shadow Directories can be accessed at http://www.ietf.org/shadow.html.¶
This Internet-Draft will expire on January 16, 2005.¶
Copyright © The Internet Society (2004). All Rights Reserved.¶
Three use cases initially motivated this proposal¶
Other working groups (like netconf) are also considering manipulating large files using HTTP GET and PUT. Sometimes the files aren't that large but the device is small or bandwidth is limited, as when phones need to add a new contact to an address book file. This feature would allow much more efficient changes to files.¶
This specification defines a new HTTP 1.1 method for patches. A new method is necessary to improve interoperability and prevent errors. The PUT method is already defined to overwrite a resource with a complete new body, and MUST NOT be reused to do partial changes. Otherwise, proxies and caches and even clients and servers may get confused as to the result of the operation.¶
Note that byte ranges are already used in HTTP to do partial downloads (GET method). However, they are not defined for uploads, and there are some missing pieces for uploads. For example, the HTTP specification has no way for the server to send errors if the byte range in a PUT is invalid. Byte ranges (or some other kind of range) could be made to work in this specification but a more flexible mechanism (one that could also encompass XML diffs) was desired, as well as a method that would not confuse caching proxies. Reliable and tested patch algorithms already exist, and this specification takes advantage of that existing work.¶
Other delta encodings are defined for HTTP in RFC 3229 [4]. That standard defines delta encodings for cache updates, not for user write operations. It does mean that servers can reuse delta format algorithms to support both that standard and this proposal.¶
This standard defines the new method PATCH to alter a single existing resource, in place, by applying a delta or diff file. The operation is atomic. Note that WebDAV MOVE and COPY requests, if supported by the HTTP server, can be useful to independently rename or copy a whole resource before applying PATCH to either the source or destination URL to modify the contents.¶
A set of changes for a resource is itself a document, called a patch document or delta. The delta format is uniquely identified through a MIME type. Servers advertise supported delta formats by advertising these MIME types, and clients specify which one they're using by including the MIME type in the request. MIME types were specifically chosen so that there would be a well-defined way for other PATCH extensions to define their own patch formats and how to use those formats.¶
This specification only defines usage of the platform-portable gdiff [9] format identified as 'application/gdiff'. Servers SHOULD support gdiff for all authorable resources, that is all resources that support PUT. Some requirements apply only to specific patch formats, and in this specification those requirements are spelled out only for gdiff.¶
The PATCH method requests that the request body (a patch document) be applied to the resource named in the Request-URI. The server MUST NOT create a new resource with the contents of the request body, although it MAY (depending on the patch document format) apply the request body to an empty entity to result in the content for the new resource. The target resource's content type MUST be one to which the patch format applies. The server MUST apply the entire patch atomically and never provide (e.g. in response to a GET during this operation) a partially-patched body. If the entire patch file cannot be successfully applied then the server MUST fail the entire request, applying none of the changes. See error handling section for details on status codes and possible error conditions.¶
In the model defined in RFC3230 [5], the patch document is modelled as an instance being sent to the server. Thus, if the server supports instance manipulations, the client MAY apply these manipulations to the patch document after it is generated (for example, a compression algorithm). On the receiving end, the server MUST undo the instance manipulation then apply the resulting document as a delta.¶
PATCH request bodies MUST NOT be cached. A cache MAY mark the resource identified in the Request-URI as stale if it sees a successful response to the PATCH request.¶
The PATCH request MUST have a body. It MUST include the Content-Type header with a MIME [1] type value identifying the delta format used in the request body. The request body MUST be in some format which has the semantics of defining a change to an existing document.¶
The PATCH request is subject to access control, which in turn may require authentication. If the server supports the WebDAV Access Control standard [8], then the PATCH request SHOULD be subject to the same access control permissions as the PUT request.¶
If the gdiff format is used:¶
Simple PATCH example
PATCH /file.txt HTTP/1.1 Host: www.example.com Content-type: application/gdiff If-Match: "e0023aa4e" Content-Length: 100 0xd1, 0xff, 0xd1, 0xff 4 249,0,0,2 2,'X','Y 249,0,2,2 249,0,1,4 0
Figure 1
This example illustrates use of the gdiff algorithm on an existing text file.¶
A successful response SHOULD have the 204 No Content status code or the 201 Created status code if a new resource was created. Either response indicates that the server successfully applied the delta and that the response contains no body.¶
The server SHOULD provide a MD5 hash of the resource entity after the delta was applied. This allows the client to verify the success of the operation. The PATCH method MUST cause the ETag to change if the resulting entity is not identical to the original. If the server supports strong ETags, the server MUST return a strong ETag for use in future client operations. The server SHOULD return the Last-Modified header in any case, but the server MUST return the Last-Modified header if ETags aren't supported.¶
Successful PATCH response to existing text file
HTTP/1.1 204 No Content Content-MD5: Q2hlY2sgSW50ZWdyaXR5IQ== ETag: "e0023aa4e"
This proposal uses the same mechanism as DeltaV to add much-needed info to base HTTP error responses. Existing HTTP status codes are not infinitely extensible but XML elements and namespaces are more so, and it's simple to treat the HTTP error code as a rough category and put detailed error codes in the body. Clients that do not use the extra information ignore the bodies of error responses.¶
The PATCH method can return the following errors. Please note that the notation "DAV:foobar" is merely short form for expressing "the 'foobar' element in the 'DAV:' namespace". It has meaning only in this specification, not on the wire. Also note that the string error codes are not meant to be displayed but instead as machine parsable known error codes (thus there is no language code).¶
"404 Not Found" can be used (with no body/error element) when the URL in by the Request-URI does not map to a resource and the server cannot apply the patch document to a new empty resource (thus this error wouldn't be used with gdiff patch documents).¶
The server advertises its support for the features described here with OPTIONS response headers. The "Allow" OPTIONS header is already defined in HTTP 1.1 to contain all the allowable methods on the addressed resource, so it's natural to add PATCH.¶
Clients also need to know whether the server supports special diff formats, so this document introduces a new OPTIONS response header "Accept-Patch". "Accept-Patch" MUST appear in the OPTIONS response for any resource where the PATCH method is shown as an allowed method.¶
OPTIONS * is not used to advertise support for PATCH because the delta formats supported are likely to change from one resource to another. A server MAY include the Accept-Patch header in response to OPTIONS *, and its value MAY be the union of known supported delta formats.¶
Accept-Patch = "Accept-Patch" ":" #media-type¶
Example: OPTIONS request and response for specific resource
[request] OPTIONS /example/buddies.xml HTTP/1.1 Host: www.example.com [response] HTTP/1.1 200 OK Allow: GET, PUT, POST, OPTIONS, HEAD, TRACE, DELETE, PATCH Accept-Patch: example/xcap+xml, application/gdiff
The examples show a server that supports PATCH generally, with two formats supported (one of them is fictional). On some resources, for example on XML files, different kinds of diff formats more appropriate to the resource may be supported.¶
PATCH is not a new concept, it first appeared in HTTP in drafts of version 1.1 written by Roy Fielding and Henrik Frystyk.¶
Thanks to Adam Roach, Chris Sharp, Julian Reschke, Geoff Clemm, Scott Lawrence, Jeffrey Mogul, Roy Fielding, Greg Stein, Jim Luther, Alex Rousskov and Jamie Lokier for review and advice on this document.¶
OPTIONS support: removed "Patch" header definition and used Allow and new "Accept-Patch" headers instead.¶
Supported delta formats: removed vcdiff and diffe as these do not have defined MIME types and did not seem to be strongly desired.¶
PATCH method definition: Clarified cache behavior.¶
Removed references to XCAP - not yet a standard.¶
Fixed use of MIME types (this "fix" now obsolete)¶
Explained how to use MOVE or COPY in conjunction with PATCH, to create a new resource based on a delta of an existing resource in a different location.¶
Clarified that MOVE and COPY are really independent of PATCH.¶
Clarified when an ETag must change, and when Last-Modified must be used.¶
Clarified what server should do if both Content-Type and IM headers appear in PATCH request.¶
Filled in missing reference to DeltaV and ACL RFCs.¶
Stopped using 501 Unsupported for unsupported delta formats.¶
Clarified what a static resource is.¶
Refixed use of MIME types for delta formats.¶
Limited the scope of some restrictions to apply only to 'gdiff' usage.¶
Copyright © The Internet Society (2004). All Rights Reserved.¶
This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this paragraph are included on all such copies and derivative works. However, this document itself may not be modified in any way, such as by removing the copyright notice or references to the Internet Society or other Internet organizations, except as needed for the purpose of developing Internet standards in which case the procedures for copyrights defined in the Internet Standards process must be followed, or as required to translate it into languages other than English.¶
The limited permissions granted above are perpetual and will not be revoked by the Internet Society or its successors or assigns.¶
This document and the information contained herein is provided on an “AS IS” basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.¶
The IETF takes no position regarding the validity or scope of any intellectual property or other rights that might be claimed to pertain to the implementation or use of the technology described in this document or the extent to which any license under such rights might or might not be available; neither does it represent that it has made any effort to identify any such rights. Information on the IETF's procedures with respect to rights in standards-track and standards-related documentation can be found in BCP-11. Copies of claims of rights made available for publication and any assurances of licenses to be made available, or the result of an attempt made to obtain a general license or permission for the use of such proprietary rights by implementors or users of this specification can be obtained from the IETF Secretariat.¶
The IETF invites any interested party to bring to its attention any copyrights, patents or patent applications, or other proprietary rights which may cover technology that may be required to practice this standard. Please address the information to the IETF Executive Director.¶