Skip to content

vfs.webdav #

WebDAV Server in V

This project implements a WebDAV server, using the vweb framework and modules from crystallib. This server allows basic file operations such as reading, writing, copying, moving, and deleting files and directories, with support for authentication and request logging.

Features

  • File Operations: Supports GET, PUT, DELETE, COPY, MOVE, and MKCOL (create directory) operations on files and directories.
  • Authentication: Basic authentication with credentials stored in memory (username:password).
  • Logging: Logs incoming requests for debugging and tracking purposes.
  • WebDAV Compliance: Implements common WebDAV HTTP methods with responses formatted as required by WebDAV clients.
  • Customizable Middleware: Custom middleware for authentication and logging.

Usage

Routes

MethodRouteDescription
GET/:path...Retrieves a file's contents.
PUT/:path...Creates or updates a file.
DELETE/:path...Deletes a file or directory.
COPY/:path...Copies a file or directory to a new location.
MOVE/:path...Moves a file or directory to a new location.
MKCOL/:path...Creates a new directory.
OPTIONS/:path...Lists supported WebDAV methods.
PROPFIND/:path...Retrieves properties of a file or directory.

Authentication

The server uses basic authentication. Set the Authorization header to Basic <base64-encoded-credentials>.

Configuration

  • Root Directory: Specify the root directory for WebDAV operations by calling new_app(root_dir: root_path).
  • User Credentials: Specify the credentials for WebDAV operations by calling new_app(username: <username>, password: <password>).

fn new_app #

fn new_app(args AppArgs) !&App

fn (App) run #

fn (mut app App) run(args RunArgs)

fn (App) not_found #

fn (mut app App) not_found() vweb.Result

fn (LockManager) lock #

fn (mut lm LockManager) lock(resource string, owner string, depth int, timeout int) !string

fn (LockManager) unlock #

fn (mut lm LockManager) unlock(resource string) bool

fn (LockManager) is_locked #

fn (lm LockManager) is_locked(resource string) bool

fn (LockManager) unlock_with_token #

fn (mut lm LockManager) unlock_with_token(resource string, token string) bool

fn (LockManager) cleanup_expired_locks #

fn (mut lm LockManager) cleanup_expired_locks()

struct AppArgs #

@[params]
struct AppArgs {
pub mut:
	server_port int = 8080
	root_dir    string            @[required]
	user_db     map[string]string @[required]
}

struct RunArgs #

@[params]
struct RunArgs {
pub mut:
	background bool
}