A collection on a WebDAV server acts as a container for resources. The name of the collection always appears in the URLs for resources inside it, determining part of the path to the resource. MKCOL is used to create new collections inside existing collections. To create a collection, the client first builds the URL for the new collection by appending the new collection's name onto the parent collection's URL. It then sends a MKCOL request to the constructed URL (see Listing 6-1).
Listing 6-1 MKCOL request and response.Request: MKCOL /hr/recruiting HTTP/1.1 Host: www.example.com Response: HTTP/1.0 201 Created Date: Sun, 29 Jul 2001 15:24:17 GMT Content-Length: 0 The server created a collection named recruiting inside the existing collection hr. The parent collection hr must already exist, but recruiting must not. If a resource named recruiting already exists, whether it's a collection or not, the request will fail. The MKCOL request does not need a body, because there's no need for additional information to create a collection. However, extensions to WebDAV may use a body, so WebDAV servers must be able to handle request bodies gracefully. If the server does not expect to see a request body, it may not look for one, and can treat the request as if it does not have a body. If the server does expect a request body but not one of the kind the client sent, it may return a 415 Unsupported Media Type status. 6.2.1 MKCOL and the Allow HeaderThe OPTIONS response for a collection typically does not show the MKCOL method in the Allow header (as shown in Listing 5-2). The HTTP specification is unclear what Allow means semantically. The WebDAV specification doesn't clarify either it doesn't mention how to treat the MKCOL method in the Allow header.
Following the same lines of reasoning, it's also unclear whether PUT should appear in the Allow header for a collection. Although a server may forbid PUT directly on a collection URL, it may allow PUT to create new resources within the collection. Clients must be prepared for either behavior and not assume that MKCOL isn't allowed just because it doesn't show up. An OPTIONS request to the magic * URL should of course show MKCOL as an allowed method, because in that case, all methods supported anywhere on the server are shown. Server implementations do seem to handle the Allow header correctly in responses to OPTIONS * that is, if the server supports OPTIONS * at all. 6.2.2 Status Codes for MKCOLThe successful response to a MKCOL request is always 201 Created. The server may refuse a MKCOL request for the usual reasons: locks are involved, permission is denied, the server couldn't match conditions provided by client, and so forth. There are also a number of special reasons that a MKCOL request can be a failure:
|