Network Working Group                                       L. Dusseault
Internet-Draft                                      Messaging Architects
Intended status: Standards Track                                J. Snell
Expires: July 23, 2009                                  January 19, 2009


                         PATCH Method for HTTP
                     draft-dusseault-http-patch-12

Status of this Memo

   This Internet-Draft is submitted to IETF in full conformance with the
   provisions of BCP 78 and 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 July 23, 2009.

Copyright Notice

   Copyright (c) 2009 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.

Abstract

   Several applications extending HTTP require a feature to do partial
   resource modification.  Existing HTTP functionality only allows a



Dusseault & Snell         Expires July 23, 2009                 [Page 1]


Internet-Draft                 HTTP PATCH                   January 2009


   complete replacement of a document.  This proposal adds a new HTTP
   method, PATCH, to modify an existing HTTP resource.


Table of Contents

   1.  Introduction . . . . . . . . . . . . . . . . . . . . . . . . .  3
   2.  The PATCH Method . . . . . . . . . . . . . . . . . . . . . . .  3
     2.1.  A simple PATCH example . . . . . . . . . . . . . . . . . .  5
     2.2.  Error handling . . . . . . . . . . . . . . . . . . . . . .  5
   3.  Advertising Support in OPTIONS . . . . . . . . . . . . . . . .  6
     3.1.  The Accept-Patch Header  . . . . . . . . . . . . . . . . .  6
     3.2.  An example OPTIONS request and response  . . . . . . . . .  7
   4.  209 Content Returned . . . . . . . . . . . . . . . . . . . . .  7
   5.  IANA Considerations  . . . . . . . . . . . . . . . . . . . . .  7
     5.1.  The 'Accept-Patch' Response Header . . . . . . . . . . . .  7
     5.2.  HTTP Status codes  . . . . . . . . . . . . . . . . . . . .  7
   6.  Security Considerations  . . . . . . . . . . . . . . . . . . .  8
   7.  References . . . . . . . . . . . . . . . . . . . . . . . . . .  8
     7.1.  Normative References . . . . . . . . . . . . . . . . . . .  8
     7.2.  Informative References . . . . . . . . . . . . . . . . . .  9
   Appendix A.  Acknowledgements  . . . . . . . . . . . . . . . . . .  9
   Appendix B.  Changes . . . . . . . . . . . . . . . . . . . . . . .  9
     B.1.  Changes from -00 . . . . . . . . . . . . . . . . . . . . .  9
     B.2.  Changes from -01 . . . . . . . . . . . . . . . . . . . . .  9
     B.3.  Changes from -02 . . . . . . . . . . . . . . . . . . . . .  9
     B.4.  Changes from -03 . . . . . . . . . . . . . . . . . . . . . 10
     B.5.  Changes from -04 . . . . . . . . . . . . . . . . . . . . . 10
     B.6.  Changes from -05 . . . . . . . . . . . . . . . . . . . . . 10
     B.7.  Changes from -06 . . . . . . . . . . . . . . . . . . . . . 10
     B.8.  Changes from -07 . . . . . . . . . . . . . . . . . . . . . 11
     B.9.  Changes from -08 . . . . . . . . . . . . . . . . . . . . . 11
     B.10. Changes from -09 . . . . . . . . . . . . . . . . . . . . . 12
     B.11. Changes from -10 . . . . . . . . . . . . . . . . . . . . . 12
     B.12. Changes from -11 . . . . . . . . . . . . . . . . . . . . . 12
   Appendix C.  Notes to RFC Editor . . . . . . . . . . . . . . . . . 12
   Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 12














Dusseault & Snell         Expires July 23, 2009                 [Page 2]


Internet-Draft                 HTTP PATCH                   January 2009


1.  Introduction

   This specification defines the new HTTP 1.1 [RFC2616] method PATCH
   that is used to apply partial modifications to a 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 can 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.

   In this document, the key words "MUST", "MUST NOT", "REQUIRED",
   "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY",
   and "OPTIONAL" are to be interpreted as described in [RFC2119].

   Furthermore, this document uses the ABNF syntax defined in Section
   2.1 of [RFC2616].


2.  The PATCH Method

   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 "patch
   document" identified by a media type.  PATCH is neither safe or
   idempotent as defined by [RFC2616], Section 9.1.  If the Request-URI
   does not point to an existing resource, and that URI is capable of
   being defined as a new resource by the requesting user agent, the
   origin server can create the resource with that URI.

   The difference between the PUT and PATCH requests is reflected in the
   way the server processes the enclosed entity to modify the resource
   identified by the Request-URI.  In a PUT request, the enclosed entity
   is considered to be a modified version of the resource stored on the
   origin server and the client is requesting that the stored version be
   replaced.  With PATCH, however, the enclosed entity contains a set of
   instructions describing how a resource currently residing on the
   origin server should be modified to produce a new version.  The
   changes described by the entity MAY result in the creation of one or
   more new resources on the server, however it is not intended that the
   body of the PATCH request be used as the content of such resources.

   The server MUST apply the entire set of changes atomically and never
   provide (e.g. in response to a GET during this operation) a
   partially-modified representation.  If the entire patch document
   cannot be successfully applied then the server MUST fail the entire
   request, applying none of the changes.  The determination of what
   constitutes a successful PATCH can vary depending on the patch



Dusseault & Snell         Expires July 23, 2009                 [Page 3]


Internet-Draft                 HTTP PATCH                   January 2009


   document and the type of resource being modified.  The actual method
   for determining how to apply the patch document to the resource is
   defined entirely by the origin server.  See Error Handling in
   Section 2.2 for details on status codes and possible error
   conditions.

   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, unless
   the response includes appropriate Cache-Control or Expires header
   fields or the response uses the 209 Content Returned status code as
   defined in Section 4.  The 303 (See Other) response can be used to
   direct the user agent to retrieve a cacheable resource.

   Collisions from multiple requests are more dangerous than PUT
   collisions, because a patch document that is not operating from a
   known base point may corrupt the resource.  Clients wishing to apply
   a patch document to a known entity can first acquire the strong ETag
   of the resource to be modified, and use that Etag in the If-Match
   header on the PATCH request to verify that the resource is still
   unchanged.  If a strong ETag is not available for a given resource,
   the client can use If-Unmodified-Since as a less-reliable safeguard.

   Note that entity-headers contained in the request apply only to the
   contained patch document and MUST NOT be applied to the resource
   being modified.  Thus, a Content-Language header could be present on
   the request but it would only mean (for whatever that's worth) that
   the patch document had a language.  Servers SHOULD NOT store such
   headers except as trace information, and SHOULD NOT use such header
   values the same way they might be used on PUT requests.  Therefore,
   this document does not specify a way to modify a document's Content-
   Type or Content-Language value through headers, though a mechanism
   could well be designed to achieve this goal through a patch document.

   There is no guarantee that a resource can be modified with PATCH.
   Further, it is expected that different patch document formats will be
   appropriate for different types of resources and that no single
   format will be appropriate for all types of resources.  Therefore,
   there is no single default patch document format that implementations
   are required to support.  Servers MUST ensure that a received patch
   document is appropriate for the type of resource identified by the
   Request-URI.









Dusseault & Snell         Expires July 23, 2009                 [Page 4]


Internet-Draft                 HTTP PATCH                   January 2009


2.1.  A simple PATCH example

   PATCH /file.txt HTTP/1.1
   Host: www.example.com
   Content-Type: application/example
   If-Match: "e0023aa4e"
   Content-Length: 100

   [description of changes]

   This example illustrates use of a hypothetical patch document on an
   existing resource.

   Successful PATCH response to existing text file

   HTTP/1.1 204 No Content
   ETag: "e0023aa4f"
   Content-MD5: Q2hlY2sgSW50ZWdyaXR5IQ==

2.2.  Error handling

   There are several known conditions under which a PATCH request can
   fail.

   Malformed patch document:  Can be specified using a 400 (Bad Request)
      when the server finds that the patch document provided by the
      client was not properly formatted.  The definition of badly
      formatted depends on the patch document chosen, but generally if
      the server finds it cannot handle the patch due to the
      serialization of the patch document, this response ought to be
      appropriate.
   Unsupported patch document:  Can be Specified using a 415
      (Unsupported Media Type) when the client sends a patch document
      format that the server does not support for the resource
      identified by the Request-URI.  Such a response SHOULD include an
      Accept-Patch response header as described in Section 3.1 to notify
      the client what patch document formats are supported.
   Unprocessable request:  Can be specified with a 422 (Unprocessable
      Entity) ([RFC4918], Section 11.2) when the server understands the
      patch document and the syntax of the patch document appears valid,
      but the server is incapable of processing the request.  There are
      a number of situations that could lead to such a result, for
      example:
      *  The client attempted to apply a patch document to an empty or
         non-existent resource, but the patch document chosen cannot be
         applied to an empty or non-existent resource.





Dusseault & Snell         Expires July 23, 2009                 [Page 5]


Internet-Draft                 HTTP PATCH                   January 2009


      *  The client attempted to apply a structural modification and the
         structures assumed to exist did not exist (e.g. a patch which
         specifies changing element 'foo' to element 'bar' but element
         'foo' doesn't exist).
      *  The client attempted to modify a resource in a way that would
         cause the resource to become invalid.  For instance, a
         modification to a well-formed XML document that would cause it
         to no longer be well-formed.
      *  The client attempted to modify a resource that has multiple
         representations but the server was unable to choose which
         representation to modify.
   Conflicting modification:  Specified with a 412 (Precondition Failed)
      when a client uses either the If-Match or If-Unmodified-Since
      request headers and attempts to apply a patch document to a
      resource whose state has changed since the patch was created.  If
      the server detects a possible conflicting modification and neither
      the If-Match or If-Unmodified-Since request headers are used, the
      server can return a 409 (Conflict) response.
   Concurrent modification:  When a server receives multiple concurrent
      requests to modify a resource, those requests SHOULD be queued and
      processed in the order in which they are received.  If a server is
      incapable of queuing concurrent requests, all subsequent requests
      SHOULD be rejected with a 409 (Conflict) until the first
      modification request is complete.

   Other HTTP status codes can also be used under the appropriate
   circumstances.

   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.


3.  Advertising Support in OPTIONS

   A server can advertise its support for the PATCH method by adding it
   to the listing of allowed methods in the "Allow" OPTIONS response
   header defined in HTTP/1.1.

3.1.  The Accept-Patch Header

   Clients also need to know whether the server supports specific patch
   document formats, so this specification introduces a new response
   header "Accept-Patch" used to specify the patch document formats
   accepted by the server.  "Accept-Patch" MUST appear in the OPTIONS
   response for any resource that supports the use of the PATCH method.
   The presence of the "Accept-Patch" header in response to any method
   is an implicit indication that PATCH is allowed on the resource



Dusseault & Snell         Expires July 23, 2009                 [Page 6]


Internet-Draft                 HTTP PATCH                   January 2009


   identified by the Request-URI.
   Accept-Patch = "Accept-Patch" ":" ( "*" | #media-type )

   The Accept-Patch header specifies a comma separated listing of media-
   types as defined by [RFC2616], Section 3.7.  The asterisk character
   "*" can be used to indicate that any patch format is accepted.

3.2.  An example OPTIONS request and response

   [request]

   OPTIONS /example/buddies.xml HTTP/1.1
   Host: www.example.com

   [response]

   HTTP/1.1 200 OK
   Allow: GET, PUT, POST, OPTIONS, HEAD, DELETE, PATCH
   Accept-Patch: application/example, text/example

   The examples show a server that supports PATCH generally using two
   hypothetical patch document formats.


4.  209 Content Returned

   The 209 "Content Returned" status code can be used to indicate that a
   response is equivalent to what would have been returned with a 200
   status code response to a GET sent to the URI immediately following
   the successful completion of the request.


5.  IANA Considerations

5.1.  The 'Accept-Patch' Response Header

   The 'Accept-Patch' response header should be added to the permanent
   registry (see [RFC3864]).

   Header field name:  Accept-Patch
   Applicable Protocol:  HTTP
   Author/Change controller:  IETF
   Specification document:  this specification

5.2.  HTTP Status codes

   This specification defines the 209 (Content Returned) status code
   (Section 4) to be updated in the registry at



Dusseault & Snell         Expires July 23, 2009                 [Page 7]


Internet-Draft                 HTTP PATCH                   January 2009


   <http://www.iana.org/assignments/http-status-codes>.


6.  Security Considerations

   The security considerations for PATCH are nearly identical to the
   security considerations for PUT ([RFC2616], Section 9.6).  These
   include authorizing requests (possibly through access control and/or
   authentication) and ensuring that data is not corrupted through
   transport errors or through accidental overwrites.  Whatever
   mechanisms are used for PUT can be used for PATCH as well.  The
   following considerations apply specially to PATCH.

   A document that is patched might be more likely to be corrupted than
   a document that is overridden in entirety, 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 patch documents 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.


7.  References

7.1.  Normative References

   [RFC2119]  Bradner, S., "Key words for use in RFCs to Indicate
              Requirement Levels", BCP 14, RFC 2119, March 1997.

   [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.



Dusseault & Snell         Expires July 23, 2009                 [Page 8]


Internet-Draft                 HTTP PATCH                   January 2009


7.2.  Informative References

   [RFC4918]  Dusseault, L., "HTTP Extensions for Web Distributed
              Authoring and Versioning (WebDAV)", RFC 4918, June 2007.


Appendix A.  Acknowledgements

   PATCH is not a new concept, it first appeared in HTTP in drafts of
   version 1.1 written by Roy Fielding and Henrik Frystyk and also
   appears in RFC 2068.

   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.


Appendix B.  Changes

B.1.  Changes from -00

   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.

B.2.  Changes from -01

   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.

B.3.  Changes from -02

   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



Dusseault & Snell         Expires July 23, 2009                 [Page 9]


Internet-Draft                 HTTP PATCH                   January 2009


   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.

B.4.  Changes from -03

   Various typographical, terminology consistency, and other minor
   clarifications or fixes.

B.5.  Changes from -04

   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.

B.6.  Changes from -05

   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.

B.7.  Changes from -06

   The reliance on RFC 3229 defined patch documents 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.




Dusseault & Snell         Expires July 23, 2009                [Page 10]


Internet-Draft                 HTTP PATCH                   January 2009


   The Accept-Patch response header has been redefined as a listing of
   media-ranges, similar to the Accept request header.

   Added James Snell as a co-author.

B.8.  Changes from -07

   Terminology change from "delta encoding" to "patch document"

   Added clarification on the safety and idempotency of PATCH

   Updated the caching rules of PATCH responses

   200 responses MUST include a representation of the modified resource.
   204 responses are used to indicate successful response without
   returning a representation.

   Suggest using 422 Unprocessable Entity to indicate that a properly
   formatted patch document cannot be processed

   Clarify the use of 412 and 409 to indicate concurrent and conflicting
   resource modifications.

   Added registration for the Accept-Patch header.

   Relaxed the requirements for the use of If-Match and If-Unmodified-
   Since.

   Add language that clarifies the difference between PUT and PATCH.

   Add language that clarifies the issues with PATCH and Content
   Negotiation.

   Use of Accept-Patch on any response implies that PATCH is supported.

   Add language advising caution when pipelining PATCH requests.

B.9.  Changes from -08

   Addition of the 209 Content Returned status code

   Addition of the Prefer header field mechanism

   Removed the paragraph discussing the use of 200+Content-Location.
   This is replaced by the 209 Content Returned status code.






Dusseault & Snell         Expires July 23, 2009                [Page 11]


Internet-Draft                 HTTP PATCH                   January 2009


B.10.  Changes from -09

   Move the prefer header to a separate document

   Restructure the document sections.

B.11.  Changes from -10

   Remove paragraph about pipelined requests.  This is covered
   adequately by RFC2616.

   Remove paragraph about content negotiation.  This is covered
   adequately by RFC2616.

   Explicitly indicate that PATCH can be used to create new resources.

   Remove recommendation for servers to provide strong etags.  This is
   recommendation is implied and does not need to be explicitly.

   Change Allow-Patch to a listing of media-type and not media-range.

B.12.  Changes from -11

   Fix section links.

   State that this uses RFC2616-style ABNF.

   Fix grammar for Accept-Patch.

   Remove requirements for handling entity-headers on PATCH and replace
   with general discussion of issues and consequences of having no
   handling requirements.

   Update Security Considerations to make it clear what security
   considerations for PUT are, for comparison.


Appendix C.  Notes to RFC Editor

   The RFC Editor should remove this section and the Changes section.











Dusseault & Snell         Expires July 23, 2009                [Page 12]


Internet-Draft                 HTTP PATCH                   January 2009


Authors' Addresses

   Lisa Dusseault
   Messaging Architects
   180 Peel Street, Suite 333
   Montreal, QC  H3C 2G7
   Canada

   Email: lisa.dusseault@messagingarchitects.com


   James M. Snell

   Email: jasnell@gmail.com
   URI:   http://www.snellspace.com




































Dusseault & Snell         Expires July 23, 2009                [Page 13]