WebDAV server with TwistedMatrix - Part 2 / X

this is a follow-up to WebDAV server with TwistedMatrix -- Part 1 / X where i have cleaned up the code somewhat. i can hardly believe that this is actually all you need to do:

from twisted.internet import reactor
from twisted.web2.dav import static
from twisted.web2 import server, channel

site = server.Site(static.DAVFile("/Users/vincent/Desktop/test"))
9998, channel.HTTPFactory(site))

you can now connect to your localhost on port 9998.

there are a few catches, though:
  • the twisted dav server is only DAV-level 1 compliant (i.e. it doesn't support locking). However, clients such as OS X 10.4's built-in DAV client require level 2 compliance (not that they really need it). a workaround is the following: in twisted/web2/dav/ change the following line as indicated in the comment:
    def davComplianceClasses(self): 
    return ("1",) # Add "2" when we have locking
  • OS X 10.3's built-in client (and likely 10.4's as well) as well as a bunch of other ones don't support redirection, which twisted does for requests on directories performed with a trailing "/" on the URI. consequently, directories are not (properly) rendered by the OS X 10.3 client (see the ticket). A workaround is to comment out the return RedirectResponse in twisted/web2/dav/ .
Related Entries:
WebDAV server with TwistedMatrix -Part 1 / X

WebDAV server with TwistedMatrix -Part 1 / X

you can find an updated version of the code presented here in the follow-up post.

apple's wilfredo sanchez recently contributed a working DAV implementation to the twistedmatrix networking framework. i intend to use both DAV and twisted matrix for our upcoming storage framework, so this contribution is just in time. ;-)

being fresh and hot off the press, documentation is sparse to nonexistent, so i intend to document my way through this jungle -- and maybe eventually contribute something back.

i have completed the first step of getting the code about two weeks ago: you'll have to get it from subversion, and then was a bit baffled by how the code tied together. it turns out it's actually quite easy and an hour ago i just got the first (ultra-buggy) self-hosted webdav volume mounted on my mac desktop -- so here you go (

import os.path, time
#from twisted.web2 import server, http, channel, resource
from twisted.web2.dav import static
from twisted.web2 import server, channel, resource
from twisted.web2 import http_headers, responsecode
from twisted.web2.dav import *
from twisted.web2.dav.method import *

site = server.Site(static.DAVFile("/Users/vincent/Desktop"))

# Standard twisted application Boilerplate
from twisted.application import service, strports
application = service.Application("demoserver")
s = strports.service('tcp:9998', channel.HTTPFactory(site))
after setting PATH and PYTHONPATH to the appropriate values, you can then launch the server from the shell using e.g.: twistd -ny
Related Entries:
WebDAV server with TwistedMatrix - Part 2 / X
1-2/2 twisting values since 1994