[Twisted-web] Need help implementing WebDAV

Andrew Bennetts twisted-web@twistedmatrix.com
Wed, 24 Dec 2003 11:59:32 +1100


On Tue, Dec 23, 2003 at 06:16:44PM -0500, Christopher Armstrong wrote:
> Thorsten Henninger wrote:
> >Hi all,
> >
> >I need some help implementing the WebDAV protocoll for Twisted.Web.
[...]
> >
> >I do not understand, how to solve this with twisted web.
> >My first guess is, that I have to do something similar as done in 
> >Twisted.web.xmlrpc ?
> >And how to I implement the protocoll? do I have to inherit from 
> >twisted.protocols.http?
> 
> No, xmlrpc isn't involved at all, and I don't _think_ you need to 
> subclass the http protocol. Mostly it will involve writing a 
> twisted.web.resource.Resource subclass that handles all the various 
> WebDAV Methods in its render(request) method. You will have to learn a 

...And subclassing Resource is how xmlrpc does it.  So Thorsten is right --
"do something similar as done in Twisted.web.xmlrpc".

> lot about the request object, which is defined in 
> twisted.web.server.Request (it subclasses twisted.protocols.http.Request).

Also, iirc, WebDAV involves several new HTTP-level methods, e.g. PROPFIND.
twisted/web/server.py says its possible to define these per-resource:

"""
# Support for other methods may be implemented on a per-resource basis.
supportedMethods = ('GET', 'HEAD', 'POST')
"""

Reading the code, it's actually kinda the opposite: it's possible to raise
UnsupportedMethod on a per-resource basis, but by default resources usually
allow any method, and just treat unrecognised methods as GET (e.g.
static.File will happily accept FDSJFJKSDFD as a valid method!).

I've opened http://twistedmatrix.com/bugs/issue446 to discuss a suggestion
to improve this behaviour.

Anyway, you don't need to subclass t.p.http to support new methods, you can
do it from the resource.  I hope this makes it clearer to you how to go
about implementing WebDAV :)

-Andrew.