Apache Week
   
   Issue 228, 29th December 2000:  

Copyright ©2020 Red Hat, Inc

In this issue


Feature: Web Authoring and HTTP

Traditionally, HTTP has only been used for web browsing, not web authoring. In situations where the author of a web site does not have direct access to the file-system which is being served, a protocol is used such as NFS, or a version control system which allows remote access, such as CVS. Alternatively, less privileged authors, who are using a dial-up Internet Service Provider, might be given FTP access to an area on a web server.

Introduction to HTTP

Before giving a description of WebDAV, it is useful to give a brief introduction to HTTP itself. The protocol consists of a request: a request message sent by the client to the server, followed by a response: the reply to the message, sent from the server back to the client.

There are three important elements of an HTTP request: the method, the URI, and the headers. The method describes the type of the request. The HTTP specification, RFC 2616, defines eight different methods, from the familiar GET, to the obscure TRACE. The URI identifies the resource on which the method is intended to operate. Headers provide any extra information about the request that is required.

A syntactically valid (but meaningless) HTTP request and the response is given below. It uses the FOOBAR method, includes three headers "Host", "Something", and "Another", and is target at the resource "/sample/uri.html". The response uses the "501 Method Not implemented" status code, telling the client that the server does not understand the request.

  FOOBAR /sample/uri.html HTTP/1.1
  Host: www.somewhere.com
  Something: else
  Another: header

  HTTP/1.1 501 Method Not Implemented
  Date: Mon, 16 Oct 2000 15:19:09 GMT
  Server: Apache/1.3.12 (Unix) DAV/1.0.2
  Connection: close
  Allow: GET, HEAD, OPTIONS, TRACE
  ...

New HTTP methods

During web browsing, the only HTTP methods that are normally used are GET, to retrieve documents, and POST, to submit form data back to the server. The WebDAV specification, RFC 2518, describes a set of new methods which allow clients to publish documents, and manipulate a remote repository in a variety of ways to meet the needs of web authoring. The methods fall into three groups:

  1. PROPFIND and PROPPATCH; for querying and manipulating properties.
  2. LOCK and UNLOCK; for locking purposes.
  3. MOVE, COPY and MKCOL; for basic repository manipulation.

In addition to the new methods, WebDAV refines the definition of the PUT and DELETE methods, which are already present in the HTTP specification.

Basic web publishing

The PUT method, as covered in a previous feature article, provides the most basic form of web publishing. This method is used to upload new or changed documents to the server.

WebDAV introduces the concept of a collection of resources to HTTP. A collection is analogous to a directory in traditional file-system terms: it has a name which ends in a /, and is a container for both normal resources, and also other collections. Collections can be created using the MKCOL method, which is similar to creating directories using the mkdir command.

  MKCOL /dav/newcollection/ HTTP/1.0
  Host: test.webdav.org

  HTTP/1.1 201 Created
  Server: Apache/1.3.11 (Unix) DAV/1.0.2
  Content-Type: text/html
  Date: Mon, 16 Oct 2000 09:10:06 GMT
  ...

The last two methods required for basic web authoring are the COPY and MOVE methods. These methods can operate in one of two ways: on a collection resource, they can recurse down an entire tree of resources, or alternatively, they can just operate on a single resource (of any type). The Depth HTTP header is used by the client to indicate which mode of operation is desired for a particular request; Depth: infinity meaning operate recursively, and Depth: 0 meaning operate only on a single resource.

Properties

WebDAV allows you to define properties on resources. Two types of properties are used: live properties, which are defined by the server, store information like the last date on which the document was modified. Dead properties are used by clients as simple data stores. An example of a dead property is the name of the author of the page.

The first method which is used with properties is PROPFIND: used to simply request all properties available on a document, or alternatively, just a specific set of properties. XML is used in the request body to give the parameters for the PROPFIND request, and also in the response, to list the property names and their values. The Depth header is also used with PROFIND requests: taking the values 0 and infinity as before, meaning in this case "give properties for a single resource only", or "give properties for all resources in this collection and below" respectively. The value 1 is also allowed, which requests properties on a collection resource, and it's immediate descendants only, without recursing into any child collections. A simple request for the properties "getlastmodified" and "getcontentlength" is given below: (the values returned for these properties are highlighted in italics)

  PROPFIND /dav/test.html HTTP/1.1
  Host: test.webdav.org
  Depth: 0
  Content-type: text/xml
  Content-Length: 174

  <?xml version="1.0" encoding="utf-8" ?>
  <propfind xmlns="DAV:">
    <prop>
      <getlastmodified/>
      <getcontentlength/>
    </prop>
  </propfind>

  HTTP/1.1 207 Multi-Status
  Server: Apache/1.3.11 (Unix) DAV/1.0.2
  Content-Type: text/xml; charset="utf-8"
  Date: Fri, 13 Oct 2000 13:51:25 GMT

  <?xml version="1.0" encoding="utf-8"?>
  <D:multistatus xmlns:D="DAV:">
  <D:response xmlns:lp0="DAV:" xmlns:lp1="http://apache.org/dav/props/">
  <D:href>/dav/test.html</D:href>
  <D:propstat>
  <D:prop>
  <lp0:getlastmodified>Fri, 13 Oct 2000 12:51:56 GMT</lp0:getlastmodified>
  <lp0:getcontentlength>105</lp0:getcontentlength>
  </D:prop>
  <D:status>HTTP/1.1 200 OK</D:status>
  </D:propstat>
  </D:response>
  </D:multistatus>

The PROPPATCH method, similarly, uses an XML request body to specify the changes which should be made to a set of properties. PROPPATCH requests are made up of a combination of the following two operations:

  • delete a named property
  • submit a new value for a named property

Locking

A lot of web authoring will involve more than one person working on a site at the sime time. Under these circumstances the lost update problem can occur, where two authors download a document and make some changes, then later, both authors upload their changes again, one set overwriting the other.

WebDAV provides a mechanism which can be used to prevent this situation, by allowing authors to lock a document while they are editing it. Once an author has locked a document, they are guaranteed that nobody else will be able to upload changes to the document.

The WebDAV specification makes locking support optional for server implementors. The level of server support for WebDAV is defined to in one of two classes: and Class 1, all requirements are met for basic web authoring, and Class 2, which extends Class 1 to include locking support.

WebDAV servers

The mod_dav module adds WebDAV support to an Apache 1.3 server. mod_dav has been under development for two years, and is currently at version 1.0.2. The module has also been integrated into the Apache 2.0 source tree, and is distributed as part of the recent alpha 7 release.

Commercial WebDAV servers are available from Microsoft, Xythos, and Novell, amongst others.

On-line Storage Sites

The on-line storage market has eagerly embraced WebDAV, with sites like Sharemation, MyDocsOnline, and Driveway all offering access to private or shared WebDAV repositories for free.

A walk on the client side

Microsoft are providing strong support for WebDAV on the client side: Internet Explorer 5 is provided with "Web Folders", which allow the user to view and manipulate a WebDAV repository inside the web browser. Office 2000 also supports editing web pages in-place using DAV, and makes use of the locking methods to prevent the lost update problem as described above. Microsoft's web publishing package FrontPage, ironically, lacks WebDAV support. Adobe GoLive 5 also supports WebDAV.

There are several Open Source WebDAV projects. cadaver provides a command-line interface similar to the ubiquitous ftp client. For Macintosh users, Goliath has a familiar Finder-like interface.

For more information, refer to the list hosted at the webdav.org site hosts of open source and commercial projects with WebDAV support.