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.
|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|
The following COPY request (/Example/Folders/ => /Copy/) copies the following structure:
To create the following:
Request (Code Snippet)
.... COPY /Example/Folders/ HTTP/1.1 DESTINATION: /Copy/ OVERWRITE: F ....
This example repeats the previous example, as the folder structure already exists it is overwriting it, as opposed to creating it.
.... COPY /Example/Folders/ HTTP/1.1 DESTINATION: /Copy/ OVERWRITE: T ....
In this example the folder "Copy" must already exist. If it doesn't then a 404 Not Found will be returned.
.... COPY /Example/Folders/howto.txt HTTP/1.1 DESTINATION: /Copy/howto.txt OVERWRITE: F ....