WEBDAV Handler for Rack

Matthias Georgi 003c17e80e Merge pull request #24 from pho3nixf1re/travis 10 years ago
bin ac2d08f6a7 passing the root is cool 11 years ago
lib 7b904b9d7d Moved the rack request and response objects to class variables on the 10 years ago
spec 7ecf338e75 Fix: multi-status res charset surrounded by quotes 11 years ago
.gitignore f51f4189b9 Add file to ignore 11 years ago
.travis.yml 70cc14c053 Added travisci configuration. 10 years ago
CHANGELOG.md eca46fc313 No need to force the response.status. As of Rack 1.2, Rack::Response is initialized with 200 by default and Rack::Response#finish automatically casts the value to integer. 13 years ago
Gemfile 7f9a41039e Gem: Typo 12 years ago
Gemfile.lock 24ed3e63f4 Retrocompatibility 11 years ago
LICENSE f218b08d66 initial commit 15 years ago
README.md f89d96c8f4 Make it obvious which parameters must be optional 11 years ago
Rakefile 906435949b Run RSpec against multiple platforms. 13 years ago
rack_dav.gemspec 24ed3e63f4 Retrocompatibility 11 years ago

README.md


RackDAV - Web Authoring for Rack

RackDAV is Handler for Rack, which allows content authoring over HTTP. RackDAV brings its own file backend, but other backends are possible by subclassing RackDAV::Resource.

Install

Just install the gem from RubyGems:

$ gem install rack_dav

Quickstart

If you just want to share a folder over WebDAV, you can just start a simple server with:

$ rack_dav

This will start a WEBrick server on port 3000, which you can connect to without authentication.

Rack Handler

Using RackDAV inside a rack application is quite easy. A simple rackup script looks like this:

require 'rubygems'
require 'rack_dav'

use Rack::CommonLogger

run RackDAV::Handler.new(:root => '/path/to/docs')

Implementing your own WebDAV resource

RackDAV::Resource is an abstract base class and defines an interface for accessing resources.

Each resource will be initialized with a path, which should be used to find the real resource.

RackDAV::Handler needs to be initialized with the actual resource class:

RackDAV::Handler.new(:resource_class => MyResource)

RackDAV needs some information about the resources, so you have to implement following methods:

  • children: If this is a collection, return the child resources.

  • collection?: Is this resource a collection?

  • exist?: Does this recource exist?

  • creation_date: Return the creation time.

  • last_modified: Return the time of last modification.

  • last_modified=(time): Set the time of last modification.

  • etag: Return an Etag, an unique hash value for this resource.

  • content_type: Return the mime type of this resource.

  • content_length: Return the size in bytes for this resource.

Most importantly you have to implement the actions, which are called to retrieve and change the resources:

  • get(request, response): Write the content of the resource to the response.body.

  • put(request, response): Save the content of the request.body.

  • post(request, response): Usually forbidden.

  • delete: Delete this resource.

  • copy(dest): Copy this resource to given destination resource.

  • move(dest): Move this resource to given destination resource.

  • make_collection: Create this resource as collection.

  • lock(locktoken, timeout, lockscope=nil, locktype=nil, owner=nil): Lock this resource. If scope, type and owner are nil, refresh the given lock.

  • unlock(token): Unlock this resource

Note, that it is generally possible, that a resource object is instantiated for a not yet existing resource.

For inspiration you should have a look at the FileResource implementation. Please let me now, if you are going to implement a new type of resource.

RackDAV on GitHub

Download or fork the project on its Github page