[−][src]Crate webdav_handler
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 for HTTP servers like hyper
, actix
,
warp
, etc. Either as a correct and complete HTTP handler for files (GET/HEAD)
or as a handler for the complete Webdav protocol. In the last case, you can
mount it as a remote filesystem: Linux, Windows, MacOS all have support built-in
to mount Webdav filesystems.
Interface.
It has an interface similar to the Go x/net/webdav package:
- the library contains an HTTP handler.
- you supply a filesystem for backend storage, which can optionally implement reading/writing DAV properties.
- you can supply a locksystem that handles webdav locks.
With some glue code, this handler can be used from HTTP server libraries/frameworks such as hyper. (See examples/hyper.rs).
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 filesystemMemFs
: 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 OSX/Windows.
Example.
Example server that serves the /tmp directory in r/w mode. You should be able to mount this network share from Linux, OSX and Windows.
use webdav_handler::{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::new(None, LocalFs::new(dir, false, false, false), Some(FakeLs::new())); 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 { dav_server.handle(req).await } }; Ok::<_, hyper::Error>(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)); }
Modules
body | Definitions for the Request and Response bodies. |
davpath | Utility module to handle the path part of an URL as a filesytem path. |
fakels | Fake locksystem (to make Windows/MacOS work). |
fs | Contains the structs and traits that define a filesystem backend. |
localfs | Local filesystem access. |
ls | Contains the structs and traits that define a |
memfs | Simple in-memory filesystem. |
memls | Simple in-memory locksystem. |
Structs
AllowedMethods | A set of allowed |
DavConfig | Configuration of the handler. |
DavHandler | The webdav handler struct. |
Enums
Method | HTTP Methods supported by DavHandler. |