5.1 WebDAV URLs and Feature Discovery

WebDAV uses HTTP URLs, but there are some differences in what the URLs mean to the client. This topic is intimately tied to feature discovery, so I've combined these two considerations, including how WebDAV extends the OPTIONS request and response.

5.1.1 Discovering WebDAV Support

Usually, the client software starts out with a URL typed in by a user, sent in email, or linked from another Web page. Starting with just a URL:

http://example.com:8080/hr/ergonomics/posture.doc

This is obviously an HTTP URL and a HTTP resource, but how can the client know if it's also a WebDAV URL and a WebDAV resource? The client needs to be able to find out in order to know if the server will accept methods like MOVE, COPY, PROPFIND, and PROPPATCH on that URL. The client can discover this through the OPTIONS request and response, as shown in Listing 5-1.

Listing 5-1 OPTIONS on a WebDAV resource.

Request:

 OPTIONS /hr/ergonomics/posture.doc HTTP/1.1 Host: www.example.com graphics/enter.gif 

Response:

 HTTP/1.1 200 OK Date: Mon, 30 Jul 2001 00:30:15 GMT Server: Apache/1.3.14 (Unix) DAV/1.0.2 DAV: 1,2 MS-Author-Via: DAV Allow: OPTIONS, GET, HEAD, DELETE, TRACE, PROPFIND,        PROPPATCH, COPY, MOVE, PUT, LOCK, UNLOCK Accept-Ranges: bytes graphics/enter.gif 

The DAV header indicates that this resource supports WebDAV. It shows whether the server supports WebDAV Class 1 features alone or both WebDAV Class 1 and 2 features. The DAV header contains comma-separated values, where the value 1 indicates Class 1 support, and the value 2 indicates Class 2 support. All WebDAV servers are required to support Class 1, which covers everything in RFC2518 other than locking. Class 2 includes locking as well.

We have already looked at a couple of these headers. The Allow header shows all the methods supported by the resource (Section 3.7.2), and the Accept-Ranges header shows that the server can accept byte-range requests (Section 3.7.12).

MS-Author-Via Header

Microsoft defined the MS-Author-Via header in order to indicate which protocol the client should use to author a Web page. Some Microsoft client software won't use WebDAV unless this header is present with the value DAV.

This header is not specified or defined in any standard; however, it is also used by some non-Microsoft WebDAV servers in order to interoperate with Microsoft Web authoring client software.


5.1.2 URLs to Collections

All WebDAV collections have URLs as well, very much like ordinary resources. WebDAV specifies that collection URLs end with a slash character (/ ). Although servers generally accept incoming collection URLs that do not end in a slash, servers should always generate collection URLs that do end in a slash.

http://example.com:8080/hr/ergonomics/

Collection URLs and Trailing Slash

graphics/roadt_icon.jpg

The WebDAV RFC recommends that when a client requests a collection without including the trailing slash, the server should respond with a success message and a Content-Location header containing the correct URL. Theoretically, the client will use the full URL from then on. However, IE 5.0 and Netscape 4.7 ignore the Content-Location header and continue to use the URL without the trailing slash.

This is more problematic than it sounds, because browsers handle relative URLs by appending the relative URL to the requested URL. With the trailing slash missing, the browser could construct URLs poorly. For example, the client could create:

http://example.com:8080/hr/ergonomicsindex.html

rather than

http://example.com:8080/hr/ergonomics/index.html

A server could use the 301 Moved Permanently response to force the client to accept the proper URL (at the cost of an extra roundtrip).


Just as with a regular resource, a WebDAV client must use an OPTIONS request to find out if a URL ending in a trailing slash points to a WebDAV resource, as shown in Listing 5-2.

Listing 5-2 OPTIONS response for a WebDAV collection.
 HTTP/1.1 200 OK Date: Sat, 27 Oct 2001 19:16:54 GMT Server: Apache/1.3.19 (Unix) DAV/1.0.2 MS-Author-Via: DAV Allow: OPTIONS, PUT, LOCK, PROPFIND, PROPPATCH, UNLOCK,        DELETE, MOVE, COPY DAV: 1,2 graphics/enter.gif 

Based on this response, the client can be sure that the resource exists and is a WebDAV resource, but there's nothing reliable to prove that the resource is a collection.

The client should not rely on the format of the URL or on the OPTIONS response to determine if the resource is a collection. WebDAV allows servers to omit the trailing slash, so the URL is not a reliable indicator. The Allow header value might be a more reliable tool, but servers differ slightly in the methods they advertise in this header for a collection. The official way to tell if a resource is a collection is to use the resourcetype property (see Section 7.5.8).

5.1.3 Deconstructing WebDAV URLs

Since the path part of a WebDAV URL follows some well-defined rules (unlike the path part of an HTTP URL), clients can use those rules in reverse to figure out other valid URLs that may also be WebDAV resources. The only reliable way for a client to discover the parent of a given resource is by parsing its URL.

Imagine that the user clicks on the following link in email or on a Web page, and the WebDAV client has no prior knowledge of the resources on this server:

http://example.com:8080/hr/ergonomics/posture.doc

The client can discover that /hr/ is a WebDAV-compliant collection by querying its properties. Once it knows that, the client can deduce further facts:

  • Because /hr/ is a collection, /hr/ergonomics/ is also a collection.

  • ergonomics is a child of the "hr" collection.

  • posture.doc is a child of the "ergonomics" collection

Now the client knows about three different resources on the WebDAV repository and can make behavioral predictions. For example, a list of the children of /hr/ergonomics/ will include posture.doc. If posture.doc is then deleted or moved to another collection, then /hr/ergonomics/ will no longer contain posture.doc.

One result of the WebDAV URL rules is that every operation that affects the name or parent collection of a resource also changes its URL. We'll see shortly how the MOVE method can be used either to rename a resource or move it to another directory, both of which will alter the URL of the resource.

5.1.4 Limits to HTTP URL Decomposition

It's important to remember that some elements in the path of a WebDAV URL may not be WebDAV collections. Some of the early parts of the path might have another meaning to the server.

For example, a WebDAV server can be implemented using the Java servlet engine. Servlets are often configured to use addresses of the form:

http://example.com/servlet/servlet-name

The path fragment servlet is an instruction to the Web software to invoke the servlet engine, and the fragment servlet-name is an instruction to the servlet engine to run a particular servlet. Let's say a WebDAV servlet is configured as:

http://example.com/servlet/dav

If that URL points to a regular Java servlet, then the client can query a number of different URLs to see if they are WebDAV collections. Table 5-1 lists what the client finds.

Sometimes administrators want to use the same server or hostname to host multiple applications. For example, a server called multi.example.com may host several HTTP hierarchies with different functionality:


http://multi.example.com/mail     hosts a Web-based mail GUI
http://multi.example.com/dav      hosts a WebDAV repository
http://multi.example.com/cal      hosts a Web-based calendar

graphics/excd_icon.jpg

Because these three addresses all refer to Web-based applications, each URL will respond successfully to an HTTP OPTIONS request. However, the three responses will be different. For the mail and calendar services, an OPTIONS response would look something like the regular HTTP OPTIONS response shown in Section 3.3.7. Only the second URL, where a WebDAV repository is hosted, will show WebDAV support through the DAV response header. The client now knows that only certain parts of the namespace support WebDAV functionality.

Table 5-1. Sample URLs and Possible OPTIONS Responses

URL

What an OPTIONS Response Indicates

http://example.com/

An OPTIONS response without a DAV: header indicates that this is a normal Web server URL.

http://example.com/servlet/

An OPTIONS response without a DAV: header indicates that this is a normal Web server URL. The URL happens to point to a Java servlet engine.

http://example.com/servlet/dav/

An OPTIONS response with a DAV: header indicating Class 1 and Class 2 support. The URL happens to point to a Java servlet engine that implements the WebDAV specification.

If the server allows clients to browse the repository but not lock the entire repository, the Allow header might show support for PROPFIND but not LOCK.

http://example.com/servlet/dav/ accounting/

An OPTIONS response with a DAV: header indicating Class 1 and Class 2 support. The Allow header shows all the methods appearing in Listing 5-2. Thus, the resource is a full WebDAV resource that happens to be hosted by a Java servlet.

Unfortunately, early releases of Windows XP had a serious problem decomposing WebDAV URLs. When a WebDAV repository is mapped to a drive letter using the Windows XP WebDAV drivers, the repository root must respond as a WebDAV resource. Given a URL such as http://example.com/servlet/dav/accounting/, the XP software immediately does an OPTIONS request to http://example.com/. If that URL does not appear to support WebDAV, then Windows XP fails the mapping request, even though the URL it was originally given would show WebDAV support if it were queried. The next section explains how a client like Windows XP should behave.

5.1.5 Finding the Repository Root with OPTIONS

Client software sometimes attempts to find out the root of a repository. This could be desirable in order to cache server feature support information, cookies, or authentication information or to be able to mount the root of the repository once rather than have to mount separately a number of collections deep in the repository.

A naive approach to this problem would be to assume that the root of the repository is the root path element, or /. However, as we've just shown, that can fail. If a client must find the top-most directory that supports WebDAV, it may have to try every element in the path.

Given the following URL:

http://example.com/servlet/dav/accounting/index.html

then the recommended approach to determining the root of the repository is to work up the collection chain and use OPTIONS requests to find out which elements are WebDAV collections. Each time, the client should check the OPTIONS response to make sure that the resource responds and that it supports WebDAV. (Although PROPFIND could theoretically retrieve the same information and more, it's not as reliable, because PROPFIND may be subject to more permissions restrictions than OPTIONS requests.)

In this case:

  1. Send the first OPTIONS request to /servlet/dav/accounting/. Server shows WebDAV support, so we continue.

  2. Send the next OPTIONS request to /servlet/dav/. Server shows WebDAV support again, so we continue.

  3. Send the next OPTIONS request to /servlet/. Server may respond with a successful status code, but the DAV header is not in the response. Stop ascending now, because it's unlikely that http://example.com/ will support WebDAV.

  4. Mount or cache /servlet/dav/ as the root of the repository.



WebDAV. Next Generation Collaborative Web Authoring
WebDAV. Next Generation Collaborative Web Authoring
ISBN: 130652083
EAN: N/A
Year: 2003
Pages: 146

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net