The MKCOL Method

The MKCOL method allows authors to create collection on the server at a specified URL. A collection means a logical or physical grouping of resources in a hierarchy. The most simple example of a collection is a directory. Collections are also resources, who can contain other collections as well.

Here is a example of a MKCOL request:

MKCOL http://localhost/digestdav/dirA/ HTTP/1.1
Host: localhost
User-Agent: cadaver/0.22.3 neon/0.25.5
Connection: TE
TE: trailers
The corresponding successful response is:
HTTP/1.1 201 Created
Date: Thu, 01 Jun 2006 06:25:11 GMT
Server: Apache/2.2.2 (FreeBSD) mod_ssl/2.2.2 \
  OpenSSL/0.9.7e-p1 DAV/2 SVN/1.3.1 mod_jk/1.2.15
Location: http://localhost/digestdav/dirA/
Content-Length: 190
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
  <head>
    <title>201 Created</title>
  </head>
  <body>
    <h1>Created</h1>
    <p>Collection /digestdav/dirA/ has been created.</p>
  </body>
</html>
The 201 Created status code shows that the collection is created and Location header contains its URL.

If a MKCOL method is issued and the collection already exists, an unsuccessful 405 Method Not Allowed response will be returned:

HTTP/1.1 405 Method Not Allowed
Date: Thu, 01 Jun 2006 06:34:51 GMT
Server: Apache/2.2.2 (FreeBSD) mod_ssl/2.2.2
  OpenSSL/0.9.7e-p1 DAV/2 SVN/1.3.1 mod_jk/1.2.15
Allow: TRACE
Content-Length: 238
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
  <head>
    <title>405 Method Not Allowed</title>
  </head>
  <body>
    <h1>Method Not Allowed</h1>
    <p>The requested method MKCOL is not allowed for the URL
    /digestdav/dirA/.</p>
  </body>
</html>

If a MKCOL method is issued and there are no write permissions, the request will fail with a 403 Forbidden status code.

If a MKCOL method is issued to create a collection whose parent does not exist, the request fails with a 409 Conflict status code:

MKCOL http://localhost/nonexisting/dir/ HTTP/1.1
Host: localhost
User-Agent: cadaver/0.22.3 neon/0.25.5
Connection: TE
TE: trailers

HTTP/1.1 405 Method Not Allowed
Date: Sun, 11 Jun 2006 07:53:23 GMT
Server: Apache/2.2.2 (FreeBSD) mod_ssl/2.2.2 OpenSSL/0.9.7e-p1
  DAV/2 SVN/1.3.1 mod_jk/1.2.15
Allow: GET,HEAD,POST,OPTIONS,TRACE
Content-Length: 239
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
  <head>
    <title>405 Method Not Allowed</title>
  </head>
  <body>
    <h1>Method Not Allowed</h1>
    <p>The requested method MKCOL is not allowed for 
    the URL /nonexisting/dir/.</p>
  </body>
</html>



Иван Иванов 2006-06-23