- Python 98.6%
- Shell 1.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .forgejo/workflows | ||
| .githooks | ||
| .github/workflows | ||
| examples | ||
| src | ||
| tests | ||
| tools/pdisc | ||
| .gitignore | ||
| .pdisc.yaml | ||
| INDEX.md | ||
| LICENSE | ||
| project.trb | ||
| README.md | ||
| title | summary | keywords | type | updated | body_hash | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| torb/webdav: WebDAV storage driver for TorbScript | README of torb/webdav, the std/storage driver for webdav: and webdavs: references: how to use WebDavStorage, which requests each member sends and what it leaves out (whole-body PUT, no locking, no ETag handling). Read before storing files on a WebDAV server. |
|
reference | 2026-11-15 | d1ed6f63345a |
torb/webdav
WebDAV as a Storage of TorbScript: WebDavStorage reads,
lists, writes and deletes the files of Nextcloud, ownCloud, a NAS or Apache's mod_dav through the trait of
std/storage, so the program that holds a Storage does not know that its bytes are on a server.
use WebDavStorage from "torb/webdav"
fn notes(): Task<Result<List<Uri>, StorageFailure>> {
var storage = WebDavStorage user: "ada", password: "secret"
storage.writeText("webdavs://cloud.example.test/files/notes/first.txt", "one").await()?
storage.list("webdavs://cloud.example.test/files/notes").await()
}
webdav://host/path is reached over http and webdavs://host/path over https. Hand the driver to Storage.registry
and a program stores at memory:, file: and webdavs: references through one value.
What each member sends
| Member | Request | Answer |
|---|---|---|
read(uri) |
GET |
the body as Bytes; 404 is NotFound |
exists(uri) |
HEAD |
true for a success, false for 404, no failure |
list(uri) |
PROPFIND with Depth: 1, the reply read with Xml().decode |
the Uris directly below the collection, sorted, the collection itself left out; 404 is NotFound |
write(uri, content) |
PUT of the whole content |
on a 409 (a collection above the file is missing) MKCOL of the missing collections from the top down, then the PUT once more |
delete(uri) |
DELETE, which removes a collection with everything below it |
404 is NotFound |
Any other status, a reply above maximumReply (16 MiB by default) and a failed connection are
StorageFailure.Refused with the status and its reason phrase, as status 403 Forbidden.
Credentials
HTTP Basic credentials are settings of the driver, WebDavStorage user:, password:, and never part of a reference. A
reference with user information is NotAddressable, and every failure names its reference as Uri.show() writes it, so
no failure text and no show of one holds a password. Send them over webdavs:: Basic over plain webdav: is
readable on the wire.
Limits
- Whole-body
PUT. A write sends the wholeBytesin one request and a read holds the whole body in memory; there are no ranges, no chunked upload and no resume. - No locking.
LOCKandUNLOCKare not sent, so a server that requires a lock token for a write refuses it, and two writers of one file do not know of each other. - No
ETaghandling.If-MatchandIf-None-Matchare not sent and theETagof a reply is not read, so a write replaces whatever is there. - No redirects. A
301or302is aRefused; give the driver the address the server answers at. - Directory entries only by path.
listreads thehrefof eachresponseand nothing else of it: no sizes, dates or properties.
Developing
$ torb format --check . # the layout torb format writes
$ torb check src tests examples
$ torb test tests # tests/webdav.test.trb starts a WebDAV server of its own on a free port
$ torb doc --check src examples
$ torb run examples/backup.trb
The tests need no WebDAV server: tests/dav-server.trb is one over an in-memory tree, built from the Server of
std/http, and each scenario starts it on port 0.
Files
webdav/
├─ project.trb name, version, description, license
├─ src/
│ ├─ lib.trb the package: "torb/webdav" resolves to this file
│ ├─ webdav.trb WebDavStorage
│ └─ listing.trb the PROPFIND request body and the reading of the 207 reply
├─ tests/
│ ├─ webdav.test.trb every member against the test server
│ └─ dav-server.trb the test server: GET, HEAD, PUT, MKCOL, DELETE and PROPFIND over a tree in memory
├─ examples/
│ └─ backup.trb a file copied between two references
└─ .github/workflows/, .forgejo/workflows/ CI (push, pull request) and publish (tag v*)
Related
- std/storage - the
Storagetrait,MemoryStorage,FileStorageandStorage.registry. - RFC 4918 - HTTP Extensions for Web Distributed Authoring and Versioning.