Code Monkey home page Code Monkey logo

dav-server-rs's Introduction

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.

External filesystems:

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 - 2023 Messense Lv
  • Apache License, Version 2.0

dav-server-rs's People

Contributors

31core avatar aawsome avatar jikstra avatar linuscde avatar mcronce avatar messense avatar miquels avatar newam avatar peter-kehl avatar quasiyoke avatar sihuan avatar themasch avatar tmpfs avatar vigilans avatar wrenger avatar xuanwo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

dav-server-rs's Issues

Compiling with `default-features = false, , features = ["warp-compat"]` fails.

I use

dav-server = {version = "0.5.0", default-features = false, features = ["warp-compat"]

and get the following compile error:

   Compiling dav-server v0.5.7
error[E0432]: unresolved import `crate::localfs`
  --> /home/alex-dev/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dav-server-0.5.7/src/warp.rs:11:29
   |
11 | use crate::{fakels::FakeLs, localfs::LocalFs, DavHandler};
   |                             ^^^^^^^ could not find `localfs` in the crate root

For more information about this error, try `rustc --explain E0432`.
error: could not compile `dav-server` (lib) due to previous error

Note that I didn't want to use the features localfs or memfs as I want to compile on targets without libc, e.g. Windows.

Maybe we should handle the feature in warp.rs correctly? If I find time, I'll prepare a PR.

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.

http conflict with axum

I've been trying to get this working with axum however there is a dependency conflict as axum depends on v1 of the http crate.

I see you have examples for warp which uses an old version of the crate so the only direct way to support both would be a feature flag. In my case I can probably use warp instead and hopefully everyone will be on 1.0 soon.

Add OpenDAL based filesystems

Hi, OpenDAL community has an effort to implement a webdav server based on dav-server-rs. Would you like to accept a OpenDAL based filesystem in dav-server-rs directly? I believe we can merge opendal related code in dav-server-rs and oay can only handle it's own logic.

proposal: Make read_dir returns `FsStream<FsResult<Box<dyn DavDirEntry>>>`

Hi, current DavFileSystem's read_dir returns FsStream<Box<dyn DavDirEntry>>:

fn read_dir<'a>(
    &'a self,
    path: &'a DavPath,
    meta: ReadDirMeta,
) -> FsFuture<FsStream<Box<dyn DavDirEntry>>>;

This makes it hard to return error during the read process. How about making read_dir returns FsStream<FsResult<Box<dyn DavDirEntry>>>?


I'm willing to help make this change.

Open files without mounting webdav fs

Hi!
Is it possible to use the library for opening files (r/w) by clients directly from webdav server without mounting it as remote file system?
My task is to provide an user of a web-application a link to a file on webdav server for editing using native application (i.e. LibreOffice Writer). This client supports webdav protocol, however it fails to open files from dav-server (on actix_web).

Wrong `quota-used-bytes` returned for collections in `LocalFs`

DavHandler uses the used space from DavFileSystem::get_quota() only on the root collection.

On every other resource DavMetaData::size() is used instead. On LocalFs that means that every subdirectory only reports an used space of around 4096 bytes (the size of the directory index).

RFC 4331 states:

The DAV:quota-used-bytes value is the value in octets representing
the amount of space used by this resource and possibly a number of
other similar resources, where the set of "similar" meets at least
the criterion that allocating space to any resource in the set will
count against the DAV:quota-available-bytes. It MUST include the
total count including usage derived from sub-resources if
appropriate. It SHOULD include metadata storage size if metadata
storage is counted against the DAV:quota-available-bytes.

So for collections it's more correct to re-use the used space from DavFileSystem::get_quota() instead of using DavMetaData::size(), as the size of a directory as reported by the OS doesn't include the sizes of contained files on usual file systems.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.