COPY
The COPY method is used to create a duplicate of the source resource identified by the Request URI at the location in the destination resource identified by the destination header. (The destination header is a requirement)
A COPY request has three possible headers
- Depth Header: Used when copying Collections. If no depth header is submitted then the default of "infinity" will be used.
- Destination Header: States where the object will be copied to. This is a required header.
- Overwrite Header: If no overwrite header is submitted then the default of "T" will be used.
A COPY request will copy all properties of an object, however properties may be updated, such as DAV:creationdate.
A COPY request will attempt to perform as much of the copy as possible. For example if a large directory structure is copied, but part of it is unable to complete then the server will still continue to process the rest of the request providing it generates valid URL's.
COPY is unable to create new Collections, the destination URI must exist.
Status Codes
| 201 Created | The resource was copied and a new resource was created (overwrite header T) |
| 204 No Content | The resource was copied over an existing resource (overwrite header F) |
| 207 Multi Status | Parts of the copy failed |
| 403 Forbidden | Generally caused by the source and destination matching |
| 409 Conflict | An intermediate collection needs to be created |
| 412 Precondition Failed | A header check failed. i.e. overwrite is set to F but the destination URI is already mapped to a resource |
Example 1: Copying a Collection
The following COPY request (/Example/Folders/ => /Copy/) copies the following structure:
/Example/Folders/
/Example/Folders/A/
/Example/Folders/B/C/
To create the following:
/Copy/
/Copy/A/
/Copy/B/C/
Request (Code Snippet)
.... COPY /Example/Folders/ HTTP/1.1 DESTINATION: /Copy/ OVERWRITE: F ....
Response
None
Example 2: Overwriting a Collection
This example repeats the previous example, as the folder structure already exists it is overwriting it, as opposed to creating it.
Request
.... COPY /Example/Folders/ HTTP/1.1 DESTINATION: /Copy/ OVERWRITE: T ....
Response
None
Example 3: Copying a File with no overwrite
In this example the folder "Copy" must already exist. If it doesn't then a 404 Not Found will be returned.
Request
.... COPY /Example/Folders/howto.txt HTTP/1.1 DESTINATION: /Copy/howto.txt OVERWRITE: F ....
Response
None
