Dav-server-rs - Rust WebDAV server library. A fork of the webdav-handler crate.

Overview

dav-server-rs

Apache-2.0 licensed Crates.io docs.rs

A fork of the webdav-handler-rs project.

Generic async HTTP/Webdav handler

Webdav (RFC4918) is defined as HTTP (GET/HEAD/PUT/DELETE) plus a bunch of extension methods (PROPFIND, etc). These extension methods are used to manage collections (like unix directories), get information on collections (like unix ls or readdir), rename and copy items, lock/unlock items, etc.

A handler is a piece of code that takes a http::Request, processes it in some way, and then generates a http::Response. This library is a handler that maps the HTTP/Webdav protocol to the filesystem. Or actually, "a" filesystem. Included is an adapter for the local filesystem (localfs), and an adapter for an in-memory filesystem (memfs).

So this library can be used as a handler with HTTP servers like hyper, warp, actix-web, etc. Either as a correct and complete HTTP handler for files (GET/HEAD) or as a handler for the entire Webdav protocol. In the latter case, you can mount it as a remote filesystem: Linux, Windows, macOS can all mount Webdav filesystems.

Backend interfaces.

The backend interfaces are similar to the ones from the Go x/net/webdav package:

The handler in this library works with the standard http types from the http and http_body crates. That means that you can use it straight away with http libraries / frameworks that also work with those types, like hyper. Compatibility modules for actix-web and warp are also provided.

Implemented standards.

Currently passes the "basic", "copymove", "props", "locks" and "http" checks of the Webdav Litmus Test testsuite. That's all of the base RFC4918 webdav specification.

The litmus test suite also has tests for RFC3744 "acl" and "principal", RFC5842 "bind", and RFC3253 "versioning". Those we do not support right now.

The relevant parts of the HTTP RFCs are also implemented, such as the preconditions (If-Match, If-None-Match, If-Modified-Since, If-Unmodified-Since, If-Range), partial transfers (Range).

Also implemented is partial PUT, for which there are currently two non-standard ways to do it: PUT with the Content-Range header, which is what Apache's mod_dav implements, and PATCH with the X-Update-Range header from SabreDav.

Backends.

Included are two filesystems:

  • LocalFs: serves a directory on the local filesystem
  • MemFs: ephemeral in-memory filesystem. supports DAV properties.

Also included are two locksystems:

  • MemLs: ephemeral in-memory locksystem.
  • FakeLs: fake locksystem. just enough LOCK/UNLOCK support for macOS/Windows.

Example.

Example server using hyper that serves the /tmp directory in r/w mode. You should be able to mount this network share from Linux, macOS and Windows. Examples for other frameworks are also available.

use std::convert::Infallible;
use dav_server::{fakels::FakeLs, localfs::LocalFs, DavHandler};

#[tokio::main]
async fn main() {
    let dir = "/tmp";
    let addr = ([127, 0, 0, 1], 4918).into();

    let dav_server = DavHandler::builder()
        .filesystem(LocalFs::new(dir, false, false, false))
        .locksystem(FakeLs::new())
        .build_handler();

    let make_service = hyper::service::make_service_fn(move |_| {
        let dav_server = dav_server.clone();
        async move {
            let func = move |req| {
                let dav_server = dav_server.clone();
                async move {
                    Ok::<_, Infallible>(dav_server.handle(req).await)
                }
            };
            Ok::<_, Infallible>(hyper::service::service_fn(func))
        }
    });

    println!("Serving {} on {}", dir, addr);
    let _ = hyper::Server::bind(&addr)
        .serve(make_service)
        .await
        .map_err(|e| eprintln!("server error: {}", e));
}

Building.

This crate uses std::future::Future and async/await, so it only works with Rust 1.39 and up.

Testing.

RUST_LOG=dav_server=debug cargo run --example sample-litmus-server

This will start a server on port 4918, serving an in-memory filesystem. For other options, run cargo run --example sample-litmus-server -- --help

Copyright and License.

  • © 2018, 2019, 2020 XS4ALL Internet bv
  • © 2018, 2019, 2020 Miquel van Smoorenburg
  • © 2021, 2022 Messense Lv
  • Apache License, Version 2.0
Comments
  • Fix path traversal

    Fix path traversal

    Hello,

    Thanks for this Rust WebDAV implementation.

    I found a path traversal vulnerability that you should be able to reproduce by running:

    cargo run --example hyper
    

    and then:

    curl 'http://127.0.0.1:4918/%2e%2e/etc/passwd'
    

    This PR proposes a way to handle this issue. I didn't read all this crate code, this patch may no be exhaustive.

    I'm going to make a PR to https://github.com/miquels/webdav-handler-rs too.

    opened by carpusredden 1
  • Usage with axum ?

    Usage with axum ?

    Hello,

    Thanks for forking and maintaining this library. Would it be possible to make it work with axum, i.e. making DavHandler impl the axum Handler trait ?

    Thanks and best regards.

    opened by nicolaspernoud 1
  • Fix wrong XML format for supportedlock prop

    Fix wrong XML format for supportedlock prop

    As per specification from http://www.webdav.org/specs/rfc4918.html#PROPERTY_supportedlock :

    PROPERTY_supportedlock should have following format:

    <D:supportedlock> 
      <D:lockentry> 
        <D:lockscope><D:exclusive/></D:lockscope> 
        <D:locktype><D:write/></D:locktype> 
      </D:lockentry> 
      <D:lockentry> 
        <D:lockscope><D:shared/></D:lockscope> 
        <D:locktype><D:write/></D:locktype> 
      </D:lockentry> 
    </D:supportedlock> 
    

    While that returned by webdav-handler-rs is:

    <D:supportedlock> 
      <D:lockentry> 
        <D:lockscope><D:exclusive/><D:write/></D:lockscope> 
      </D:lockentry> 
      <D:lockentry> 
        <D:lockscope><D:shared/><D:write/></D:lockscope> 
      </D:lockentry> 
    </D:supportedlock> 
    

    This made webdav libraries like https://github.com/lookfirst/sardine and https://github.com/thegrizzlylabs/sardine-android report error on parsing XML returned by webdav-handler-rs (thus android apps using this library will fail to use webdav server of webdav-handler-rs). This PR fixes the format by specfication.

    This PR is also opened in https://github.com/miquels/webdav-handler-rs/pull/24. I also opened several other PR there (https://github.com/miquels/webdav-handler-rs/pull/11 and https://github.com/miquels/webdav-handler-rs/pull/25), but are related to filesystem quota feature that is mainly relevant with webdav-server-rs binary.

    opened by Vigilans 0
  • Support for CalDAV and CardDAV

    Support for CalDAV and CardDAV

    Hi,

    Is there any plan to support CalDAV and/or CardDAV ?

    There are already some required peace done in rust like: https://crates.io/crates/icalendar and https://crates.io/crates/vcard so most of the job I think is related to integration and some additional APIs, anyway probably is not too easy.

    Regards

    opened by tglman 1
  • KiB、GiB应该使用二进制方式统计

    KiB、GiB应该使用二进制方式统计

    参考Wikipedia,KiB、GiB表示的是二进制统计单位:https://en.wikipedia.org/wiki/Byte#Multiple-byte_units

    https://github.com/messense/dav-server-rs/blob/67f1b11adf99d740e4297b43c79387488904c4bc/src/handle_gethead.rs#L443

    opened by YangshengLu 0
Owner
messense
Python Backend Developer at day, Rustacean at night.
messense
Library + CLI-Tool to measure the TTFB (time to first byte) of HTTP requests. Additionally, this crate measures the times of DNS lookup, TCP connect and TLS handshake.

TTFB: CLI + Lib to Measure the TTFB of HTTP/1.1 Requests Similar to the network tab in Google Chrome or Mozilla Firefox, this crate helps you find the

Philipp Schuster 24 Dec 1, 2022
DNS Server written in Rust for fun, see https://dev.to/xfbs/writing-a-dns-server-in-rust-1gpn

DNS Fun Ever wondered how you can write a DNS server in Rust? No? Well, too bad, I'm telling you anyways. But don't worry, this is going to be a fun o

Patrick Elsen 26 Jan 13, 2023
axum-server is a hyper server implementation designed to be used with axum framework.

axum-server axum-server is a hyper server implementation designed to be used with axum framework. Features Conveniently bind to any number of addresse

null 79 Jan 4, 2023
Jex Compiler Server - Server that runs Jex code

Server that compiles and runs Jex code.

furetur 3 Nov 18, 2021
QUIC proxy that allows to use QUIC to connect to an SSH server without needing to patch the client or the server.

quicssh-rs ?? quicssh-rs is a QUIC proxy that allows to use QUIC to connect to an SSH server without needing to patch the client or the server. quicss

Jun Ouyang 18 May 5, 2023
Rust crate for configurable parallel web crawling, designed to crawl for content

url-crawler A configurable parallel web crawler, designed to crawl a website for content. Changelog Docs.rs Example extern crate url_crawler; use std:

Pop!_OS 56 Aug 22, 2021
Rust crate for scraping URLs from HTML pages

url-scraper Rust crate for scraping URLs from HTML pages. Example extern crate url_scraper; use url_scraper::UrlScraper; fn main() { let director

Pop!_OS 35 Aug 18, 2022
Safe Rust crate for creating socket servers and clients with ease.

bitsock Safe Rust crate for creating socket servers and clients with ease. Description This crate can be used for Client <--> Server applications of e

Lorenzo Torres 3 Nov 25, 2021
The netns-rs crate provides an ultra-simple interface for handling network namespaces in Rust.

netns-rs The netns-rs crate provides an ultra-simple interface for handling network namespaces in Rust. Changing namespaces requires elevated privileg

OpenAnolis Community 7 Dec 15, 2022
Rust utility crate for parsing, encoding and generating x25519 keys used by WireGuard

WireGuard Keys This is a utility crate for parsing, encoding and generating x25519 keys that are used by WireGuard. It exports custom types that can b

Fractal Networks 3 Aug 9, 2022
Rust crate providing a variety of automotive related libraries, such as communicating with CAN interfaces and diagnostic APIs

The Automotive Crate Welcome to the automotive crate documentation. The purpose of this crate is to help you with all things automotive related. Most

I CAN Hack 29 Mar 11, 2024
SOCKS5 implement library, with some useful utilities such as dns-query, socks5-server, dns2socks, udp-client, etc.

socks5-impl Fundamental abstractions and async read / write functions for SOCKS5 protocol and Relatively low-level asynchronized SOCKS5 server impleme

null 5 Aug 3, 2023
A crate for parsing HTTP rate limit headers as per the IETF draft

rate-limits A crate for parsing HTTP rate limit headers as per the IETF draft. Inofficial implementations like the Github rate limit headers are also

Matthias 3 Jul 9, 2022
⏱ Cross-platform Prometheus style process metrics collector of metrics crate

⏱ metrics-process This crate provides Prometheus style process metrics collector of metrics crate for Linux, macOS, and Windows. Collector code is man

Alisue 12 Dec 16, 2022
`prometheus` backend for `metrics` crate

metrics + prometheus = ❤️ API Docs | Changelog prometheus backend for metrics crate. Motivation Rust has at least two ecosystems regarding metrics col

Instrumentisto Team 2 Dec 17, 2022
Crate extending futures stream combinators, that is adding precise rate limiter

stream-rate-limiter Stream combinator .rate_limiter(opt: RateLimitOptions) Provides way to limit stream element rate with constant intervals. It adds

null 3 Jul 23, 2023
Minimal self-contained crate to accept file descriptors from systemd

sd-listen-fds Exposes file descriptors passed in by systemd, the Linux init daemon, without dependencies, foreign or otherwise. Enables easy implement

Benjamin Saunders 3 Aug 14, 2023
The gRPC library for Rust built on C Core library and futures

gRPC-rs gRPC-rs is a Rust wrapper of gRPC Core. gRPC is a high performance, open source universal RPC framework that puts mobile and HTTP/2 first. Sta

TiKV Project 1.6k Jan 7, 2023
A µTP (Micro/uTorrent Transport Library) library implemented in Rust

rust-utp A Micro Transport Protocol library implemented in Rust. API documentation Overview The Micro Transport Protocol is a reliable transport proto

Ricardo Martins 134 Dec 11, 2022