Network Working Group L. Dusseault Internet-Draft Xythos Expires: May 12, 2004 November 12, 2003 Partial Document Changes (PATCH Method) for HTTP draft-dusseault-http-patch-00 Status of this Memo 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 May 12, 2004. Copyright Notice Copyright (C) The Internet Society (2003). All Rights Reserved. Abstract 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. Dusseault Expires May 12, 2004 [Page 1] Internet-Draft HTTP PATCH November 2003 1. Introduction Three use cases initially motivated this proposal 1. WebDAV is used by authoring applications to store and share files on the internet. For example, Adobe Photoshop has a Workgroup feature allowing the user to browse a repository and save the file. Currently, Photoshop only publishes the file to the repository rarely, because Photoshop files are typically large and upload is slow. Worse, large uploads are more likely to be interrupted. Although HTTP provides byte range downloads, it cannot provide this simple a mechanism for uploads. 2. DeltaV extends WebDAV to do versioning. In versioning environments, a large number of files may be updated with very small changes. For example, a programmer may change the name of a function used in a hundred source files. Versioning applications typically send deltas or 'diffs' to the server to modify these files, however DetaV does not yet have this functionality. 3. The SIMPLE WG is devising a way to store and modify configuration information. The biggest feature missing from HTTP is the ability to modify information in a very lightweight manner, so that the client that decides to change its presence state from "free" to "busy" doesn't have to upload a large document. This can be accomplished through changes to a HTTP resource as well. 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 [HTTP]. 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 could be made to work in this specification but they're not the only way to do partial modifications. Since reliable and tested patch algorithms already Dusseault Expires May 12, 2004 [Page 2] Internet-Draft HTTP PATCH November 2003 exist, those are preferred. Other delta encodings are defined for HTTP in [RFC3229]. 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. That standard does not use MIME types to identify the delta algorithm, but the mapping is trivial. Dusseault Expires May 12, 2004 [Page 3] Internet-Draft HTTP PATCH November 2003 2. Mechanisms 2.1 PATCH Method The PATCH method requests that the request body (a patch document) be applied to the resource named in the Request-URI. The resource named in the Request-URI MUST already exist (the server MUST NOT create a new resource with the body of the PATCH method). The target resource's content type MUST be one to which the patch format applies. See error handling section for details on status codes and possible error conditions. PATCH bodies are not cachable. 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 value indicating what the body type is. It MUST be a format that has the semantics of defining a change to an existing document (such as gdiff or vcdiff). The PATCH request MUST also use one of the standard HTTP/1.1 mechanisms that let the server know when the request body is done. The PATCH request body length MUST NOT be indicated only by closing the connection when the body is complete, because an incomplete PATCH body could conceivably corrupt the target resource. The PATCH request MUST only be used in a context which ensures that only one user may apply a patch at a time. There are two reliable ways to do this. The first way is to find out the resource ETag at the time the body is downloaded, and use that Etag in the PATCH request to make sure the resource is still unchanged. The second way to use WebDAV LOCK/UNLOCK [WEBDAV] to reserve the file (first LOCK, then GET, then PATCH, then UNLOCK). PATCH collisions from multiple users are more dangerous than PUT collisions, because a PATCH that is not operating from a known base point may corrupt the resource. Therefore, if neither strong ETags nor LOCKS are available from the server, the client MUST use If-Last-Modified as a less-reliable safeguard. Dusseault Expires May 12, 2004 [Page 4] Internet-Draft HTTP PATCH November 2003 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 platform-portable 'gdiff' algorithm as one possible patch format. In this case the resource is a text file. 2.2 PATCH Response 2.2.1 Success Response The basic success response code for PATCH is 204 No Content. For this new method, 200 OK is not used because 200 OK implies a body in the response, and 201 Created is not used because the resource must already exist. The server SHOULD provide a MD5 hash of the content after the delta was applied. This allows the client to verify the success of the operation. If the server supports ETags, the server MUST return a strong ETag for use in future client operations. If the server does not support strong ETags, then the server MUST return the Last-Modified header instead. Successful PATCH response HTTP/1.1 204 No Content Content-MD5: Q2hlY2sgSW50ZWdyaXR5IQ== ETag: "e0023aa4e" Dusseault Expires May 12, 2004 [Page 5] Internet-Draft HTTP PATCH November 2003 2.2.2 Error handling 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. 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 English, 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). DAV:delta-format-unsupported: Used with 501 Not Supported status code. Returned by the server when it doesn't support the delta format chosen by the client. DAV:delta-format-forbidden-on-resource: Used with 403 Forbidden when the delta format chosen by the client is supported by the server but not allowed on this kind of resource. DAV:delta-format-badly-formatted: Used with 400 Bad Request when the server finds that the delta document provided by the client was badly formatted and non-compliant. DAV:delta-empty-resource: Used with 409 Conflict when the resource addressed in the Request-URI exists but is empty, and the delta format cannot be applied to an empty document. Note that some delta formats may be applied to an empty document, in which case this error wouldn't be used. DAV:patch-result-invalid: Used with 409 Conflict when the resource could be patched but the result of the patch would be a resource which is invalid. This could mean, for example, that a XML resource would become an invalid XML file if the patch specified that a close element text line should be deleted. "404 Not Found" is used with no body/error element when the URL in by the Request-URI does not map to a resource. 2.3 Delta Formats A set of changes for a resource is itself a document, called a change document or delta. Every change document format must be a registered MIME type. Servers advertise supported delta mechanisms by advertising these MIME types, and clients specify which one they're Dusseault Expires May 12, 2004 [Page 6] Internet-Draft HTTP PATCH November 2003 using by including the MIME type in the Content-Type header. This table outlines the delta format support requirements for a server supporting this proposal. Set of defined delta formats Format Specification MIME type/ Requirements GDIFF [W3C-GDIFF] application/gdiff MUST support for all document types except XML. MAY support for XML documents. Servers supporting DeltaV MUST support for ALL document types. XCAP [XCAP] text/xcap+xml MUST support for XML documents. VCDIFF [] application/vcdiff??? MAY support for all document types. DIFFE [RFC3229] ??? MAY support for all document types. ISSUES: We only have a real mime type for GDIFF so far. It would be a public service to register vcdiff and diffe as well if those are used at all. 2.4 Advertising Support in OPTIONS: Patch header The server advertises its support for the features described here with an OPTIONS response header, sent on OPTIONS requests for any resource. The Patch header on any OPTIONS response indicates that the server supports the PATCH method and at least one delta format. When the OPTIONS request addresses a specific modifiable resource, the Patch header in the response indicates which delta formats may be used for this specific resource. When an OPTIONS request addresses the server as a whole (Request-URI = "*") the Delta header in the response indicates the union of all delta formats supported by the server. OPTIONS request and response indicating Patch support [request] OPTIONS * HTTP/1.1 Host: www.example.com [response] HTTP/1.1 200 OK Patch: application/gdiff, text/xcap+xml Dusseault Expires May 12, 2004 [Page 7] Internet-Draft HTTP PATCH November 2003 References [1] van Hoff, A. and J. Payne, "Generic Diff Format Specification", August 1997. [2] Mogul, J., Krishnamurthy, B., Douglis, F., Feldmann, A., Goland, Y., van Hoff, A. and D. Hellerstein, "Delta encoding in HTTP", RFC 3229, January 2002. [3] Goland, Y., Whitehead, E., Faizi, A., Carter, S. and D. Jensen, "HTTP Extensions for Distributed Authoring - WebDAV", RFC 2518. [4] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., Masinter, L., Leach, P. and T. Berners-Lee, "Hypertext Transfer Protocol -- HTTP/1.1", June 1999. [5] Rosenberg, J., "The Extensible Markup Language (XML) Configuration Access Protocol (XCAP)", October 2003. [6] Freed, N. and N. Borenstein, "Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types", RFC 2046, November 1996. Author's Address Lisa Dusseault Xythos Software, Inc. 2064 Edgewood Dr. Palo Alto, CA 94303 US EMail: lisa@xythos.com Dusseault Expires May 12, 2004 [Page 8] Internet-Draft HTTP PATCH November 2003 Appendix A. Changes Dusseault Expires May 12, 2004 [Page 9] Internet-Draft HTTP PATCH November 2003 Intellectual Property Statement 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. Full Copyright Statement Copyright (C) The Internet Society (2003). 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 assignees. 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 Dusseault Expires May 12, 2004 [Page 10] Internet-Draft HTTP PATCH November 2003 HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Acknowledgment Funding for the RFC Editor function is currently provided by the Internet Society. Dusseault Expires May 12, 2004 [Page 11]