Skip to content

Supported WebDAV methods [v2]

Adrien Castex edited this page Jun 30, 2017 · 2 revisions

The server provides methods to implements the WebDAV specifications, but it is possible to add your own methods and to override the default methods with yours. You can do so thanks to the method method of the WebDAVServer instance. You can also manage the behaviour of the server when a requested method is not implemented thanks to the method onUnknownMethod of the WebDAVServer instance.

List of available methods

Method Description
NotImplemented Default behavior when the requested method is not implemented. It returns a 501 Not implemented to the client.
Proppatch Set/Remove properties to/from a resource.
Propfind Get information about a resource (name, properties, locks, etc...). The content is not parsed yet (making this behavior not completely compliant with the RFC4918).
Options Get the list of supported methods.
Delete Delete a resource.
Unlock Unlock a resource. It needs the Lock-Token header.
Mkcol Create a directory type resource.
Copy Copy a resource. It needs the Destination header.
Lock Lock a resource, preventing it from being written. This method can refresh a lock if the If header is provided.
Move Move a resource. It needs the Destination header.
Head Make a Get but do not send the content. Allow to test if a resource exists and if it can be read.
Post Set the content of a resource or create this one. It is an alias of the Put method. Removing the Put method will keep the Put behavior through the Post method
Put Set the content of a resource or create this one.
Get Get the content of a resource.

More information and examples

In order to get more information and to get some examples of requests, you can look at the RFC4918 page.

Adding methods

A method must follow the HTTPMethod interface :

interface HTTPMethod
{
    unchunked?(ctx : HTTPRequestContext, data : Buffer, callback : () => void) : void
    chunked?(ctx : HTTPRequestContext, inputStream : Readable, callback : () => void) : void
    isValidFor?(ctx : HTTPRequestContext, type ?: ResourceType) : boolean
}

When executed, the callback MUST always be called. This will allow the afterRequest functions to be executed and finalize the sending to the client.

If the object implements the chunked method, then this method will be called with the input body stream in the arguments. If this method is not implemented, the unchunked method will be called with the input body buffer in the arguments.

If the isValidFor method is defined, it will be used to check if the method is allowed or not on this type of resource. For instance, the method MKCOL is forbidden if the resource exists (type === undefined), but the method PUT is available only if the resource doesn't exist or if the type of the resource is a file (!type || type.isFile). This method will help to display the allowed methods for a resource in the Allow header.

The chunked method is useful if you expect a large content. It will allow the management of the request content as a stream.

The HTTPRequestContext class is the request/response manager, allowing the method to get information from the request and to send data to the client. It simplify some tasks such as finding a header without case sensitivity or getting a resource from its path.

Adding the method to the server

server.method('INFO', infoMethodExecutor);

This will tell to the server to call the infoMethodExecutor.chunked or the infoMethodExecutor.unchunked method when it receives a request with the method info (not case sensitive).

You can find the implementations of the WebDAV methods in here to get some examples.

Clone this wiki locally