]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/docs/rfc5789.txt
Merge branch 'master' of git://github.com/friendica/friendica-addons
[friendica-addons.git] / dav / SabreDAV / docs / rfc5789.txt
1
2
3
4
5
6
7 Internet Engineering Task Force (IETF)                      L. Dusseault
8 Request for Comments: 5789                                    Linden Lab
9 Category: Standards Track                                       J. Snell
10 ISSN: 2070-1721                                               March 2010
11
12
13                          PATCH Method for HTTP
14
15 Abstract
16
17    Several applications extending the Hypertext Transfer Protocol (HTTP)
18    require a feature to do partial resource modification.  The existing
19    HTTP PUT method only allows a complete replacement of a document.
20    This proposal adds a new HTTP method, PATCH, to modify an existing
21    HTTP resource.
22
23 Status of This Memo
24
25    This is an Internet Standards Track document.
26
27    This document is a product of the Internet Engineering Task Force
28    (IETF).  It represents the consensus of the IETF community.  It has
29    received public review and has been approved for publication by the
30    Internet Engineering Steering Group (IESG).  Further information on
31    Internet Standards is available in Section 2 of RFC 5741.
32
33    Information about the current status of this document, any errata,
34    and how to provide feedback on it may be obtained at
35    http://www.rfc-editor.org/info/rfc5789.
36
37 Copyright Notice
38
39    Copyright (c) 2010 IETF Trust and the persons identified as the
40    document authors.  All rights reserved.
41
42    This document is subject to BCP 78 and the IETF Trust's Legal
43    Provisions Relating to IETF Documents
44    (http://trustee.ietf.org/license-info) in effect on the date of
45    publication of this document.  Please review these documents
46    carefully, as they describe your rights and restrictions with respect
47    to this document.  Code Components extracted from this document must
48    include Simplified BSD License text as described in Section 4.e of
49    the Trust Legal Provisions and are provided without warranty as
50    described in the Simplified BSD License.
51
52
53
54
55
56
57
58 Dusseault & Snell            Standards Track                    [Page 1]
59 \f
60 RFC 5789                       HTTP PATCH                     March 2010
61
62
63 Table of Contents
64
65    1. Introduction ....................................................2
66    2. The PATCH Method ................................................2
67       2.1. A Simple PATCH Example .....................................4
68       2.2. Error Handling .............................................5
69    3. Advertising Support in OPTIONS ..................................7
70       3.1. The Accept-Patch Header ....................................7
71       3.2. Example OPTIONS Request and Response .......................7
72    4. IANA Considerations .............................................8
73       4.1. The Accept-Patch Response Header ...........................8
74    5. Security Considerations .........................................8
75    6. References ......................................................9
76       6.1. Normative References .......................................9
77       6.2. Informative References .....................................9
78    Appendix A.  Acknowledgements .....................................10
79
80 1.  Introduction
81
82    This specification defines the new HTTP/1.1 [RFC2616] method, PATCH,
83    which is used to apply partial modifications to a resource.
84
85    A new method is necessary to improve interoperability and prevent
86    errors.  The PUT method is already defined to overwrite a resource
87    with a complete new body, and cannot be reused to do partial changes.
88    Otherwise, proxies and caches, and even clients and servers, may get
89    confused as to the result of the operation.  POST is already used but
90    without broad interoperability (for one, there is no standard way to
91    discover patch format support).  PATCH was mentioned in earlier HTTP
92    specifications, but not completely defined.
93
94    In this document, the key words "MUST", "MUST NOT", "REQUIRED",
95    "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY",
96    and "OPTIONAL" are to be interpreted as described in [RFC2119].
97
98    Furthermore, this document uses the ABNF syntax defined in Section
99    2.1 of [RFC2616].
100
101 2.  The PATCH Method
102
103    The PATCH method requests that a set of changes described in the
104    request entity be applied to the resource identified by the Request-
105    URI.  The set of changes is represented in a format called a "patch
106    document" identified by a media type.  If the Request-URI does not
107    point to an existing resource, the server MAY create a new resource,
108    depending on the patch document type (whether it can logically modify
109    a null resource) and permissions, etc.
110
111
112
113
114 Dusseault & Snell            Standards Track                    [Page 2]
115 \f
116 RFC 5789                       HTTP PATCH                     March 2010
117
118
119    The difference between the PUT and PATCH requests is reflected in the
120    way the server processes the enclosed entity to modify the resource
121    identified by the Request-URI.  In a PUT request, the enclosed entity
122    is considered to be a modified version of the resource stored on the
123    origin server, and the client is requesting that the stored version
124    be replaced.  With PATCH, however, the enclosed entity contains a set
125    of instructions describing how a resource currently residing on the
126    origin server should be modified to produce a new version.  The PATCH
127    method affects the resource identified by the Request-URI, and it
128    also MAY have side effects on other resources; i.e., new resources
129    may be created, or existing ones modified, by the application of a
130    PATCH.
131
132    PATCH is neither safe nor idempotent as defined by [RFC2616], Section
133    9.1.
134
135    A PATCH request can be issued in such a way as to be idempotent,
136    which also helps prevent bad outcomes from collisions between two
137    PATCH requests on the same resource in a similar time frame.
138    Collisions from multiple PATCH requests may be more dangerous than
139    PUT collisions because some patch formats need to operate from a
140    known base-point or else they will corrupt the resource.  Clients
141    using this kind of patch application SHOULD use a conditional request
142    such that the request will fail if the resource has been updated
143    since the client last accessed the resource.  For example, the client
144    can use a strong ETag [RFC2616] in an If-Match header on the PATCH
145    request.
146
147    There are also cases where patch formats do not need to operate from
148    a known base-point (e.g., appending text lines to log files, or non-
149    colliding rows to database tables), in which case the same care in
150    client requests is not needed.
151
152    The server MUST apply the entire set of changes atomically and never
153    provide (e.g., in response to a GET during this operation) a
154    partially modified representation.  If the entire patch document
155    cannot be successfully applied, then the server MUST NOT apply any of
156    the changes.  The determination of what constitutes a successful
157    PATCH can vary depending on the patch document and the type of
158    resource(s) being modified.  For example, the common 'diff' utility
159    can generate a patch document that applies to multiple files in a
160    directory hierarchy.  The atomicity requirement holds for all
161    directly affected files.  See "Error Handling", Section 2.2, for
162    details on status codes and possible error conditions.
163
164    If the request passes through a cache and the Request-URI identifies
165    one or more currently cached entities, those entries SHOULD be
166    treated as stale.  A response to this method is only cacheable if it
167
168
169
170 Dusseault & Snell            Standards Track                    [Page 3]
171 \f
172 RFC 5789                       HTTP PATCH                     March 2010
173
174
175    contains explicit freshness information (such as an Expires header or
176    "Cache-Control: max-age" directive) as well as the Content-Location
177    header matching the Request-URI, indicating that the PATCH response
178    body is a resource representation.  A cached PATCH response can only
179    be used to respond to subsequent GET and HEAD requests; it MUST NOT
180    be used to respond to other methods (in particular, PATCH).
181
182    Note that entity-headers contained in the request apply only to the
183    contained patch document and MUST NOT be applied to the resource
184    being modified.  Thus, a Content-Language header could be present on
185    the request, but it would only mean (for whatever that's worth) that
186    the patch document had a language.  Servers SHOULD NOT store such
187    headers except as trace information, and SHOULD NOT use such header
188    values the same way they might be used on PUT requests.  Therefore,
189    this document does not specify a way to modify a document's Content-
190    Type or Content-Language value through headers, though a mechanism
191    could well be designed to achieve this goal through a patch document.
192
193    There is no guarantee that a resource can be modified with PATCH.
194    Further, it is expected that different patch document formats will be
195    appropriate for different types of resources and that no single
196    format will be appropriate for all types of resources.  Therefore,
197    there is no single default patch document format that implementations
198    are required to support.  Servers MUST ensure that a received patch
199    document is appropriate for the type of resource identified by the
200    Request-URI.
201
202    Clients need to choose when to use PATCH rather than PUT.  For
203    example, if the patch document size is larger than the size of the
204    new resource data that would be used in a PUT, then it might make
205    sense to use PUT instead of PATCH.  A comparison to POST is even more
206    difficult, because POST is used in widely varying ways and can
207    encompass PUT and PATCH-like operations if the server chooses.  If
208    the operation does not modify the resource identified by the Request-
209    URI in a predictable way, POST should be considered instead of PATCH
210    or PUT.
211
212 2.1.  A Simple PATCH Example
213
214    PATCH /file.txt HTTP/1.1
215    Host: www.example.com
216    Content-Type: application/example
217    If-Match: "e0023aa4e"
218    Content-Length: 100
219
220    [description of changes]
221
222
223
224
225
226 Dusseault & Snell            Standards Track                    [Page 4]
227 \f
228 RFC 5789                       HTTP PATCH                     March 2010
229
230
231    This example illustrates use of a hypothetical patch document on an
232    existing resource.
233
234    Successful PATCH response to existing text file:
235
236    HTTP/1.1 204 No Content
237    Content-Location: /file.txt
238    ETag: "e0023aa4f"
239
240    The 204 response code is used because the response does not carry a
241    message body (which a response with the 200 code would have).  Note
242    that other success codes could be used as well.
243
244    Furthermore, the ETag response header field contains the ETag for the
245    entity created by applying the PATCH, available at
246    http://www.example.com/file.txt, as indicated by the Content-Location
247    response header field.
248
249 2.2.  Error Handling
250
251    There are several known conditions under which a PATCH request can
252    fail.
253
254    Malformed patch document:  When the server determines that the patch
255       document provided by the client is not properly formatted, it
256       SHOULD return a 400 (Bad Request) response.  The definition of
257       badly formatted depends on the patch document chosen.
258
259    Unsupported patch document:  Can be specified using a 415
260       (Unsupported Media Type) response when the client sends a patch
261       document format that the server does not support for the resource
262       identified by the Request-URI.  Such a response SHOULD include an
263       Accept-Patch response header as described in Section 3.1 to notify
264       the client what patch document media types are supported.
265
266    Unprocessable request:  Can be specified with a 422 (Unprocessable
267       Entity) response ([RFC4918], Section 11.2) when the server
268       understands the patch document and the syntax of the patch
269       document appears to be valid, but the server is incapable of
270       processing the request.  This might include attempts to modify a
271       resource in a way that would cause the resource to become invalid;
272       for instance, a modification to a well-formed XML document that
273       would cause it to no longer be well-formed.  There may also be
274       more specific errors like "Conflicting State" that could be
275       signaled with this status code, but the more specific error would
276       generally be more helpful.
277
278
279
280
281
282 Dusseault & Snell            Standards Track                    [Page 5]
283 \f
284 RFC 5789                       HTTP PATCH                     March 2010
285
286
287    Resource not found:  Can be specified with a 404 (Not Found) status
288       code when the client attempted to apply a patch document to a non-
289       existent resource, but the patch document chosen cannot be applied
290       to a non-existent resource.
291
292    Conflicting state:  Can be specified with a 409 (Conflict) status
293       code when the request cannot be applied given the state of the
294       resource.  For example, if the client attempted to apply a
295       structural modification and the structures assumed to exist did
296       not exist (with XML, a patch might specify changing element 'foo'
297       to element 'bar' but element 'foo' might not exist).
298
299    Conflicting modification:  When a client uses either the If-Match or
300       If-Unmodified-Since header to define a precondition, and that
301       precondition failed, then the 412 (Precondition Failed) error is
302       most helpful to the client.  However, that response makes no sense
303       if there was no precondition on the request.  In cases when the
304       server detects a possible conflicting modification and no
305       precondition was defined in the request, the server can return a
306       409 (Conflict) response.
307
308    Concurrent modification:  Some applications of PATCH might require
309       the server to process requests in the order in which they are
310       received.  If a server is operating under those restrictions, and
311       it receives concurrent requests to modify the same resource, but
312       is unable to queue those requests, the server can usefully
313       indicate this error by using a 409 (Conflict) response.
314
315    Note that the 409 Conflict response gives reasonably consistent
316    information to clients.  Depending on the application and the nature
317    of the patch format, the client might be able to reissue the request
318    as is (e.g., an instruction to append a line to a log file), have to
319    retrieve the resource content to recalculate a patch, or have to fail
320    the operation.
321
322    Other HTTP status codes can also be used under the appropriate
323    circumstances.
324
325    The entity body of error responses SHOULD contain enough information
326    to communicate the nature of the error to the client.  The content-
327    type of the response entity can vary across implementations.
328
329
330
331
332
333
334
335
336
337
338 Dusseault & Snell            Standards Track                    [Page 6]
339 \f
340 RFC 5789                       HTTP PATCH                     March 2010
341
342
343 3.  Advertising Support in OPTIONS
344
345    A server can advertise its support for the PATCH method by adding it
346    to the listing of allowed methods in the "Allow" OPTIONS response
347    header defined in HTTP/1.1.  The PATCH method MAY appear in the
348    "Allow" header even if the Accept-Patch header is absent, in which
349    case the list of allowed patch documents is not advertised.
350
351 3.1.  The Accept-Patch Header
352
353    This specification introduces a new response header Accept-Patch used
354    to specify the patch document formats accepted by the server.
355    Accept-Patch SHOULD appear in the OPTIONS response for any resource
356    that supports the use of the PATCH method.  The presence of the
357    Accept-Patch header in response to any method is an implicit
358    indication that PATCH is allowed on the resource identified by the
359    Request-URI.  The presence of a specific patch document format in
360    this header indicates that that specific format is allowed on the
361    resource identified by the Request-URI.
362
363    Accept-Patch = "Accept-Patch" ":" 1#media-type
364
365    The Accept-Patch header specifies a comma-separated listing of media-
366    types (with optional parameters) as defined by [RFC2616], Section
367    3.7.
368
369    Example:
370
371    Accept-Patch: text/example;charset=utf-8
372
373 3.2.  Example OPTIONS Request and Response
374
375    [request]
376
377    OPTIONS /example/buddies.xml HTTP/1.1
378    Host: www.example.com
379
380    [response]
381
382    HTTP/1.1 200 OK
383    Allow: GET, PUT, POST, OPTIONS, HEAD, DELETE, PATCH
384    Accept-Patch: application/example, text/example
385
386    The examples show a server that supports PATCH generally using two
387    hypothetical patch document formats.
388
389
390
391
392
393
394 Dusseault & Snell            Standards Track                    [Page 7]
395 \f
396 RFC 5789                       HTTP PATCH                     March 2010
397
398
399 4.  IANA Considerations
400
401 4.1.  The Accept-Patch Response Header
402
403    The Accept-Patch response header has been added to the permanent
404    registry (see [RFC3864]).
405
406    Header field name:  Accept-Patch
407
408    Applicable Protocol:  HTTP
409
410    Author/Change controller:  IETF
411
412    Specification document:  this specification
413
414 5.  Security Considerations
415
416    The security considerations for PATCH are nearly identical to the
417    security considerations for PUT ([RFC2616], Section 9.6).  These
418    include authorizing requests (possibly through access control and/or
419    authentication) and ensuring that data is not corrupted through
420    transport errors or through accidental overwrites.  Whatever
421    mechanisms are used for PUT can be used for PATCH as well.  The
422    following considerations apply especially to PATCH.
423
424    A document that is patched might be more likely to be corrupted than
425    a document that is overridden in entirety, but that concern can be
426    addressed through the use of mechanisms such as conditional requests
427    using ETags and the If-Match request header as described in
428    Section 2.  If a PATCH request fails, the client can issue a GET
429    request to the resource to see what state it is in.  In some cases,
430    the client might be able to check the contents of the resource to see
431    if the PATCH request can be resent, but in other cases, the attempt
432    will just fail and/or a user will have to verify intent.  In the case
433    of a failure of the underlying transport channel, where a PATCH
434    response is not received before the channel fails or some other
435    timeout happens, the client might have to issue a GET request to see
436    whether the request was applied.  The client might want to ensure
437    that the GET request bypasses caches using mechanisms described in
438    HTTP specifications (see, for example, Section 13.1.6 of [RFC2616]).
439
440    Sometimes an HTTP intermediary might try to detect viruses being sent
441    via HTTP by checking the body of the PUT/POST request or GET
442    response.  The PATCH method complicates such watch-keeping because
443    neither the source document nor the patch document might be a virus,
444    yet the result could be.  This security consideration is not
445
446
447
448
449
450 Dusseault & Snell            Standards Track                    [Page 8]
451 \f
452 RFC 5789                       HTTP PATCH                     March 2010
453
454
455    materially different from those already introduced by byte-range
456    downloads, downloading patch documents, uploading zipped (compressed)
457    files, and so on.
458
459    Individual patch documents will have their own specific security
460    considerations that will likely vary depending on the types of
461    resources being patched.  The considerations for patched binary
462    resources, for instance, will be different than those for patched XML
463    documents.  Servers MUST take adequate precautions to ensure that
464    malicious clients cannot consume excessive server resources (e.g.,
465    CPU, disk I/O) through the client's use of PATCH.
466
467 6.  References
468
469 6.1.  Normative References
470
471    [RFC2119]  Bradner, S., "Key words for use in RFCs to Indicate
472               Requirement Levels", BCP 14, RFC 2119, March 1997.
473
474    [RFC2616]  Fielding, R., Gettys, J., Mogul, J., Frystyk, H.,
475               Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext
476               Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999.
477
478    [RFC3864]  Klyne, G., Nottingham, M., and J. Mogul, "Registration
479               Procedures for Message Header Fields", BCP 90, RFC 3864,
480               September 2004.
481
482 6.2.  Informative References
483
484    [RFC4918]  Dusseault, L., "HTTP Extensions for Web Distributed
485               Authoring and Versioning (WebDAV)", RFC 4918, June 2007.
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506 Dusseault & Snell            Standards Track                    [Page 9]
507 \f
508 RFC 5789                       HTTP PATCH                     March 2010
509
510
511 Appendix A.  Acknowledgements
512
513    PATCH is not a new concept, it first appeared in HTTP in drafts of
514    version 1.1 written by Roy Fielding and Henrik Frystyk and also
515    appears in Section 19.6.1.1 of RFC 2068.
516
517    Thanks to Adam Roach, Chris Sharp, Julian Reschke, Geoff Clemm, Scott
518    Lawrence, Jeffrey Mogul, Roy Fielding, Greg Stein, Jim Luther, Alex
519    Rousskov, Jamie Lokier, Joe Hildebrand, Mark Nottingham, Michael
520    Balloni, Cyrus Daboo, Brian Carpenter, John Klensin, Eliot Lear, SM,
521    and Bernie Hoeneisen for review and advice on this document.  In
522    particular, Julian Reschke did repeated reviews, made many useful
523    suggestions, and was critical to the publication of this document.
524
525 Authors' Addresses
526
527    Lisa Dusseault
528    Linden Lab
529    945 Battery Street
530    San Francisco, CA  94111
531    USA
532
533    EMail: lisa.dusseault@gmail.com
534
535
536    James M. Snell
537
538    EMail: jasnell@gmail.com
539    URI:   http://www.snellspace.com
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562 Dusseault & Snell            Standards Track                   [Page 10]
563 \f