|Individual Submission||L. Dusseault|
|Intended status: Informational||J. Snell|
|Expires: December 24, 2007||June 22, 2007|
PATCH Method for HTTP
By submitting this Internet-Draft, each author represents that any applicable patent or other IPR claims of which he or she is aware have been or will be disclosed, and any of which he or she becomes aware will be disclosed, in accordance with Section 6 of BCP 79.
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 December 24, 2007.
Copyright © The IETF Trust (2007). All Rights Reserved.
Several applications extending HTTP require a feature to do partial resource modification. Existing HTTP functionality only allows a complete replacement of a document. This proposal adds a new HTTP method, PATCH, to modify an existing HTTP resource.
This specification defines a new HTTP 1.1 [RFC2616] method PATCH that is used to apply partial modifications to a HTTP resource. 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) as defined in RFC2616. However, they are not defined for uploads, and there are some missing pieces for uploads. For example, the HTTP specification does not define a particularly informative error to send 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 delta encodings) was desired, as well as a method that would not confuse caching proxies.
The PATCH method requests that a set of changes described in the request entity be applied to the resource identified by the Request-URI. The set of changes is represented in a format called a "delta encoding" identified by a media type and MUST include sufficient information to allow the server to recreate the changes necessary to convert the original version of the resource into the desired version. The server MUST NOT create a new resource with the contents of the request body, although it MAY (depending on the delta encoding) apply the request body to an empty resource. The recipient of the entity MUST NOT ignore any Content-* (e.g. Content-Range) headers that it does not understand or implement and MUST return a 501 (Not Implemented) response in such cases.
The server SHOULD always 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 delta encoding 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.
The actual method for determining how to apply the delta encoding to the resource is defined entirely by the origin server.
If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those entries SHOULD be treated as stale. Responses to this method are not cacheable.
Collisions from multiple requests are more dangerous than PUT collisions, because a delta encoding that is not operating from a known base point may corrupt the resource. Therefore, the client MUST verify that it is applying the delta encoding to a known entity by first acquiring the strong ETag of the resource to be modified, and using that Etag in the If-Match header on the PATCH request to make sure the resource is still unchanged. If a strong ETag is not available for a given resource, the client MUST use If-Unmodified-Since as a less-reliable safeguard.
Servers SHOULD provide strong ETags for all resources for which the PATCH method is supported.
Servers advertise the types of delta encoding documents supported for PATCH, and clients specify which one they're using by including its media type in the request using the Content-Type request header.
Simple PATCH example
PATCH /file.txt HTTP/1.1 Host: www.example.com Content-type: application/delta If-Match: "e0023aa4e" Content-Length: 100 [description of changes]
This example illustrates use of a hypothetical delta encoding on an existing text file.
A response with a 2xx status code indicates that the PATCH request was a success. The server MAY include a representation of the modified resource in the response and MAY include appropriate Content-* headers to allow the client to verify the success of the operation.
As with PUT, the PATCH method MUST change the resource's ETag 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 MUST return the Last-Modified header if it does not support strong ETags.
Successful PATCH response to existing text file
HTTP/1.1 200 OK ETag: "e0023aa4f" Content-MD5: Q2hlY2sgSW50ZWdyaXR5IQ== Content-Type: text/plain [modified resource]
There are several known conditions under which a PATCH request can fail.
Other status codes MAY also be used under the appropriate circumstances. For example, an unauthenticated user may be prompted to authenticate, in order to use PATCH, with "401 Unauthorized". An authenticated user who does not have sufficient privilege to use PATCH may receive a "403 Forbidden" response.
The entity body of error responses SHOULD contain enough information to communicate the nature of the error to the client. The content-type of the response entity can vary across implementations. XML error responses as defined by [RFC2518bis] MAY be used.
HTTP/1.1 409 Conflict Content-Type: text/plain; charset="utf-8" Content-Length: xxx Invalid result
The server advertises its support for the PATCH method with OPTIONS response headers. The "Allow" OPTIONS header is already defined in HTTP 1.1 to contain all the allowed methods on the addressed resource, so the server MUST add PATCH if it is allowed.
Clients also need to know whether the server supports specific delta encoding formats, so this document introduces a new response header "Accept-Patch" used to specify the delta encoding formats accepted by the server. "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 patch 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 encodings for all types of resources.
Accept-Patch = "Accept-Patch" ":" #( media-range )
The Accept-Patch header specifies a listing of media ranges as defined by RFC2616 Section 14.1. Note that, unlike the HTTP Accept request header, the Accept-Patch header does not use quality factors.
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: application/diff, application/diff+xml
The examples show a server that supports PATCH generally using two hypothetical delta encodings.
There is no guarantee that a resource can be modified with PATCH. Further, it is expected that different delta encodings will be appropriate for different types of resources and that no single delta encoding will be appropriate for all types of resources. Therefore, there is no single default delta encoding that implementations are required to support. Servers MUST ensure that a received delta encoding is appropriate for the type of resource identified by the Request-URI.
Byte-based or binary delta encodings are useful for many types of resources as long as the server stores resources identically to the way they're presented on the wire (or can behave as if it does).
Character-based delta encodings operate on a variable number of bytes depending on the length of each character, thus correct use of these algorithms depends on the encoding of the resource. Such delta encodings MUST either use the same character set encoding as the resource being modified or MUST produce an otherwise valid result. The validity of the result is dependent on the type of resource being modified.
Structure-based delta encodings allow changes to be applied independent of exact formats or canonicalizations. For example, a delta encoding format targeted at the modification of XML-based resources may allow for the insertion or deletion of elements and attributes without concern for the exact serialization of those in the modified resource.
This document does not specify any actions for IANA.
The security considerations for PATCH are nearly identical to the security considerations for PUT. In addition, one might be concerned that a document that is patched might be more likely to be corrupted, but that concern can be addressed through the use of mechanisms such as conditional requests using ETags and the If-Match request header.
Sometimes an HTTP intermediary might try to detect viruses being sent via HTTP by checking the body of the PUT/POST request or GET response. The PATCH method complicates such watch-keeping because neither the source document nor the patch document might be a virus, yet the result could be. This security consideration is not materially different from those already introduced by byte-range downloads, downloading patch documents, uploading zipped (compressed) files and so on.
Individual delta encodings will have their own specific security considerations that will likely vary depending on the types of resources being patched. The considerations for patched binary resources, for instance, will be different than those for patched XML documents.
|[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.|
Open Source Application Foundation
2064 Edgewood Dr.
Palo Alto, CA 94303
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, Jamie Lokier, Joe Hildebrand, Mark Nottingham and Michael Balloni for review and advice on this document.
OPTIONS support: removed "Patch" header definition and used Allow and new "Accept-Patch" headers instead.
Supported delta encodings: 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 RFC.
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 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 encodings.
Clarified what a static resource is.
Refixed use of MIME types for patch formats.
Limited the scope of some restrictions to apply only to usage of required diff format.
Various typographical, terminology consistency, and other minor clarifications or fixes.
Moved paragraphs on ACL and RFC3229 interoperability to new section.
Added security considerations.
Added IANA considerations, registration of new namespace, and discontinued use of "DAV:" namespace for new elements.
Added example of error response.
Due to various concerns it didn't seem likely the application/gdiff registration could go through so switching to vcdiff as required diff format, and to RFC3229's approach to specifying diff formats, including use of the IM header.
Clarified what header server MUST use to return MD5 hash.
Reverted to using 501 Unsupported for unsupported delta encodings.
The reliance on RFC 3229 defined delta encodings has been factored out in favor of delta encodings identified by MIME media type.
The required use of DeltaV-based error reporting has been removed in favor of using basic HTTP status codes to report error conditions.
The Accept-Patch response header has been redefined as a listing of media-ranges with quality factors, similar to the Accept request header.
Added James Snell as a co-author.
The RFC Editor should remove this section and the Changes section.
Copyright © The IETF Trust (2007).
This document is subject to the rights, licenses and restrictions contained in BCP 78, and except as set forth therein, the authors retain all their rights.
This document and the information contained herein are provided on an “AS IS” basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY, THE IETF TRUST AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM 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 Rights 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; nor does it represent that it has made any independent effort to identify any such rights. Information on the procedures with respect to rights in RFC documents can be found in BCP 78 and BCP 79.
Copies of IPR disclosures made to the IETF Secretariat 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 implementers or users of this specification can be obtained from the IETF on-line IPR repository at http://www.ietf.org/ipr.
The IETF invites any interested party to bring to its attention any copyrights, patents or patent applications, or other proprietary rights that may cover technology that may be required to implement this standard. Please address the information to the IETF at firstname.lastname@example.org.