WebDAV
Web Distributed Authoring and Versioning (WebDAV) is a collection of HTTP extensions that provides collaboration capabilities to clients directly on an HTTP web server. WebDAV provides concurrency control and namespace operations, and in general facilitates collaboration by providing a platform that is not only readable but can be written to by multiple clients.
Features and capabilities
WebDAV allows clients to create, modify, and manage files that reside on the server. In addition to the contents of each file, WebDAV maintains meta-information related to the author and editors. For example, WebDAV records properties such as the creation date and last modification date, accompanied by the names of the clients responsible for creating files and making changes.
Namespace management gives control over web pages and offers functions to copy or move a web page inside of a specific namespace.
WebDAV also offers file locking, which is a tool to prevent the accidental overwriting of data.
Collections
WebDAV uses an entity called a collection, which is either a resource or a set of resources. A collection can be put under version control and as such, a specific version of a collection is not modifiable. A collection can be thought of as a directory hierarchy at a specific point in time.
HTTP verbs
The extensions to HTTP include a set of new verbs and headers that can be utilized as a part of an HTTP request. The verbs include Make Collection (MKCOL), MOVE, COPY, LOCK, UNLOCK, and PROPPATCH.
MKCOL (Make Collection)
The MKCOL method is used to create a new collection. Depending on the result of the HTTP request, the server will return one of several responses, as follows:
If the collection is successfully created then the server will return HTTP response 201 Created.
The 403 Forbidden HTTP status code will be returned if either the server does not allow collections to be created at the specified location in its namespace, or the parent collection of the URI already exists and does not accept members, or both.
HTTP status code 405 Method Not Allowed will be returned if MKCOL is executed on a mapped URL. It can only be used with an unmapped URL.
If the 409 Conflict HTTP status code is returned by the server then it means that the collection cannot be created because one or more intermediate collections do not exist. The server will not create intermediate collections automatically.
If the HTTP request is for an entity type that it does not support then it will return the HTTP error 415 Unsupported Media Type status code.
If there is insufficient space to add the new collection and save the state of the resource afterward then the 507 Insufficient Storage HTTP status code will be returned.
MOVE
The MOVE method is used to move a collection from one URI to another. If another resource already exists at the destination then it will be replaced, subject to the presence and value of the Overwrite header. Overwrite is assumed to be true but if it fails, the server will return HTTP error 412 Precondition Failed as the HTTP status code. The move-to location is specified using the Destination header.
COPY
The COPY method is used to make a copy of a collection from a source URI, placing it at the destination. The Destination header is used to specify this.
LOCK
The LOCK method is used to put a shared or exclusive lock on the resource.
UNLOCK
The UNLOCK method will remove a lock from a resource. The Lock-Token header is required to submit the token to release the resource. If not all of the resources are released then the method will fail.
PROPFIND
The PROPFIND method will retrieve properties from a resource, stored in XML format. It can also be used to retrieve the structure of the collection (i.e. the directory hierarchy) at a URL.
PROPPATCH
The PROPPATCH method can be employed to change or delete properties associated with a resource. Several modifications or deletions can be accomplished in a single atomic action.
WebDAV HTTP headers
The standard HTTP headers also apply to WebDAV requests, a small number of additional headers were defined for it specifically. These are Overwrite, If, and Lock-token.
Overwrite header
The Overwrite header specifies whether an operation can allow a destination resource to be replaced in the event of a MOVE or COPY command.
If header
The If header is a condition that is intended to work similarly to HTTP If-Match. The difference is that WebDAV If can handle lock tokens in addition to ETags.
Lock-Token header
The Lock-Token header is required by the UNLOCK method. It specifies the token that is required to release the resource from, and the method will fail if not all of the resources are successfully unlocked.
HTTP headers – other considerations
There are certain restrictions placed on the use of the other HTTP headers. For example, when executing the MOVE method, setting the Depth header to Depth: infinity
is the only valid option. The specification is to be consulted for fine details when this functionality is implemented.
WebDAV versus FTP
Depending on the use case, FTP or SFTP may be more used instead of WebDAV, although WebDAV is often a better choice. It is important to recall that WebDAV uses a single TCP connection to manage collections that are stored on the server. Simple file uploads or downloads can be done using FTP and in the case of a single file, will work similarly to WebDAV. However, if many small files are being transferred, and depending on the FTP client, it may use many connections. In this scenario, WebDAV is more efficient than FTP because everything is done without having to initiate new connections.
Another issue is that TCP is easier to configure than FTP when it comes to firewalls, proxies, and other intermediaries. If FTP is not the transfer method of choice for the server then it may not be optimally configured. Finally, Compression is standard for HTTP, whereas, for FTP, Mode Z compression needs to be enabled if it is supported by both client and server.
Takeaway
Web Distributed Authoring and Versioning (WebDAV) is a set of extensions to HTTP that can be used to interact with files on a web server, whereas servers are typically used as read-only entities. It serves as a platform for resource collaboration with multiple contributors. A resource, or a set of resources, is referred to as a collection. In addition to the standard HTTP verbs and headers, several others are defined specifically for working with WebDAV collections.