Config File¶
webdav.toml file¶
Convert .json to .toml¶
please search convert json toml in your browser.
When the file does not exist¶
When the file /data/webdav.toml(.json) does not exist, http://127.0.0.1/ will map to the /data directory.
logging output¶
WARNING: load config value from file[/data/webdav.json] failed, [Errno 2] No such file or directory: '/data/webdav.json'
INFO: [asgi_webdav.webdav] ASGI WebDAV(v0.3.1) starting...
INFO: [asgi_webdav.distributor] Mapping Prefix: / => file:///data
INFO: [asgi_webdav.auth] Register Account: username, allow:[''], deny:[]
INFO: [uvicorn] Started server process [7]
INFO: [uvicorn] Uvicorn running on http://0.0.0.0:80 (Press CTRL+C to quit)
When the file exists¶
When the file exists, the mapping relationship is defined by the file content.
Example¶
[[account_mapping]]
username = "username"
password = "password"
permissions = [ "+" ]
[[account_mapping]]
username = "litmus"
password = "password"
permissions = [ "+^/$", "+^/litmus", "-^/litmus/other" ]
[[account_mapping]]
username = "guest"
password = "password"
permissions = [ ]
[anonymous]
enable = true
[[provider_mapping]]
prefix = "/"
uri = "file:///data/root"
read_only = true
[[provider_mapping]]
prefix = "/provider"
uri = "memory:///"
read_only = true
[[provider_mapping]]
prefix = "/provider/fs"
uri = "file:///data/litmus"
[[provider_mapping]]
prefix = "/provider/memory"
uri = "memory:///"
ignore_property_extra = false
[[provider_mapping]]
prefix = "/~"
uri = "file:///data/home"
home_dir = true
More example please check examples/config/*.toml in codebase.
logging output¶
INFO: [asgi_webdav.server] ASGI WebDAV Server(v1.3.2) starting...
INFO: [asgi_webdav.auth] Register Account: username, allow:[''], deny:[]
INFO: [asgi_webdav.auth] Register Account: litmus, allow:['^/$', '^/litmus'], deny:['^/litmus/other']
INFO: [asgi_webdav.auth] Register Account: guest, allow:[], deny:[]
INFO: [asgi_webdav.auth] Register Account: anonymous, allow:['^/public'], deny:[]
INFO: [asgi_webdav.web_dav] Mapping Prefix: / --[ReadOnly]--> file:///data/root
INFO: [asgi_webdav.web_dav] Mapping Prefix: /provider --[ReadOnly]--> memory:///
INFO: [asgi_webdav.web_dav] Mapping Prefix: /provider/fs --> file:///tmp
INFO: [asgi_webdav.web_dav] Mapping Prefix: /provider/memory --> memory:///
INFO: [asgi_webdav.web_dav] Mapping Prefix: /~ --[Home]--> file:///data/home/{user name}
INFO: [asgi_webdav.server] ASGI WebDAV Server running on http://localhost:8000 (Press CTRL+C to quit)
Config Object¶
root object
- Introduced in 0.1
- Last updated in 1.6.0
| Key | Use For | Value Type | Default Value |
|---|---|---|---|
| account_mapping | auth | list[User] |
[] |
| anonymous | auth | Anonymous |
Anonymous() |
| http_basic_auth | auth | HTTPBasicAuth |
HTTPBasicAuth() |
| http_digest_auth | auth | HTTPDigestAuth |
HTTPDigestAuth() |
| provider_mapping | mapping | list[Provider] |
[] |
| hide_file_in_dir | rules | HideFileInDir |
HideFileInDir() |
| guess_type_extension | rules | GuessTypeExtension |
GuessTypeExtension() |
| text_file_charset_detect | rules | TextFileCharsetDetect |
TextFileCharsetDetect() |
| compression | response | Compression |
Compression() |
| cors | response | CORS |
CORS() |
| enable_dir_browser | response | bool |
true |
| template_dir | response | str |
None |
| template_failure_policy | response | str |
"fallback" |
| logging | other | Logging |
"Logging()" |
| sentry_dsn | other | str |
None |
for Template System¶
- Unreleased
The template system allows customising HTML output for the directory browser, 401 error page, and admin pages. Bundled templates are used as fallback when custom files are not provided.
template_dir¶
- Type:
str - Default:
None(use bundled templates only) - Config file key:
template_dir - Environment variable:
WEBDAV_TEMPLATE_DIR - CLI flag:
--template-dir
Points to a directory containing template subdirectories. The directory structure must mirror the bundled layout:
my-templates/
base.html # optional shared layout
dir_browser/
index.html # override the directory listing page
row_parent.html # override the parent (..) row
row_directory.html # override directory rows
row_file.html # override file rows
styles.css # override CSS (served via /_/static/dir_browser/styles.css)
admin/
index.html # override the admin index page
logging.html # override the admin logging page
error/
401.html # override the 401 error page
Only the files you place in your custom directory will override the bundled defaults. Missing files fall back to the bundled versions. This allows partial customisation — for example, overriding only error/401.html while keeping all other templates as bundled.
An empty or whitespace-only template_dir is treated as not set. This also
applies to /_/static/, which is served from the custom directory (when set)
and then the bundled directory — the working directory is never added.
template_failure_policy¶
- Type:
str - Default:
"fallback" - Allowed values:
"fallback","stop" - Config file key:
template_failure_policy - Environment variable:
WEBDAV_TEMPLATE_FAILURE_POLICY - CLI flag:
--template-failure-policy
Any other value is rejected at startup, whether it comes from the config file,
the environment variable or the CLI: the server logs a critical message and
exits with status 1. A misspelled policy is never silently replaced by
fallback.
At startup, every template in the manifest is parsed and its extends/include
dependencies are checked for syntax errors. A dependency that cannot be found is
only logged as a warning, because Jinja resolves it at render time and
{% include ... ignore missing %} or a conditional {% extends %} may never
need it. When validation fails:
fallback: log the broken template and the underlying Jinja error, discard the whole custom tree, serve only the bundled templates, and remove the custom directory from the/_/static/roots.stop: log a critical message and exit with status 1.
Custom and bundled templates are never mixed within a rendered page after a validation failure.
A custom tree may be partial by design. To detect a tree copied from a different
release, place the server version in an optional VERSION file at the root of
template_dir. A mismatch logs a warning and the server continues to start.
Template Variables¶
Directory browser (dir_browser/):
| Template | Variables |
|---|---|
index.html |
path, parent, items, version, current_time |
row_parent.html |
parent.href |
row_directory.html |
item.href, item.name, item.type, item.modified |
row_file.html |
item.href, item.name, item.type, item.size, item.modified |
401 error (error/):
| Template | Variables |
|---|---|
401.html |
message |
Admin pages (admin/):
| Template | Variables |
|---|---|
index.html |
(none) |
logging.html |
messages |
Templates use Jinja2 syntax and can use {% extends %} and {% include %}.
HTML autoescaping is enabled and missing variables
raise an error. User-controlled values are passed to templates raw and escaped by
Jinja2.
Static files such as styles.css are served from disk by the static middleware
and are never parsed by Jinja2; startup validation only checks *.html
templates.
for Authentication¶
User Object¶
- Introduced in 0.3.1
- Last updated in 0.7
| Key | Value Type | Default Value |
|---|---|---|
| username | str | - |
| password | str | - |
| permissions | list[str] | [] |
| admin | bool | false |
- When the value of
administrue, the user can access the web page/_/admin/xxx
Permissions Format/Example¶
- Introduced in 0.3.1
- Last updated in 0.3.1
| Value | Allow | Deny |
|---|---|---|
["+"] |
Any | - |
["-"] |
- | Any |
["+^/$"] |
/ |
/path |
["+^/path"] |
/path,/path/sub |
/other |
["+^/path", "-^/path/sub2"] |
/path,/path/sub1 |
/path/sub2 |
Anonymous Object¶
- Introduced in 1.6
- Last updated in 1.6
| Key | Value Type | Default Value |
|---|---|---|
| enable | bool | false |
| user | User |
User("anonymous", "", ["+"]) |
| allow_missing_auth_header | bool | true |
- Anonymous accounts can be authenticated via HTTP header at any time, just like normal users.
- If
allow_missing_auth_headeristrue, anonymous requests will be treated as being requested by an anonymous account.
More detail, please see howto.
HTTPBasicAuth Object¶
- Introduced in 1.5
- Last updated in 1.6
| Key | Value Type | Default Value | Changed |
|---|---|---|---|
| cache_type | str | memory |
v1.5 |
| cache_timeout | int | -1 |
v1.5 |
cache_type allowed value¶
bypassmemoryexpiring
cache_timeout¶
- Unit: second
- Supported
cache_type:expiring
| Value | Meaning |
|---|---|
| -1 | cache does not expire (default) |
| 0 | cache is disabled |
| >0 | seconds until each cache entry expires |
HTTPDigestAuth Object¶
- Introduced in 0.7
- Last updated in 2.0.2
| Key | Value Type | Default Value |
|---|---|---|
| enable | bool | false |
| enable_rule | str | `` |
| disable_rule | str | `` |
- When
enableistrue, thedisable_ruleis valid - When
enableisfalse, theenable_ruleis valid
for URL Mapping¶
Provider Object¶
- Introduced in 0.1
- Last updated in 2.2.x
| Key | Value Type | Default Value |
|---|---|---|
| prefix | str | - |
| uri | str | - |
| type | str | "" |
| home_dir | bool | false |
| read_only | bool | false |
| ignore_property_extra | bool | true |
| put_buffer_max_size | int | 1048576 |
- When
read_onlyistrue; it is a read only directory, include subdirectories. - When
ignore_property_extraistrue; The Provider ignores the extra property, based on the Provider's implementation. put_buffer_max_size: PUT bodies up to this size are buffered in memory so the whole write (stat + temp file + rename) runs as one worker-thread hop; file system provider only.0disables buffering (always stream to the temp file).
Provider Type¶
- Some providers require a
typeto ensure proper identification. eg:webhdfs
| Provider | Type | Required |
|---|---|---|
| FileSystemProvider | fs |
- |
| MemoryProvider | memory |
- |
| WebHDFSProvider | webhdfs |
+ |
Home Directory¶
- When
home_diristrue, it is the home directory. Theprefixrecommends using/~or/home. - When
home_diristrueandprefixis/~anduriisfile:///data/homesandusernameisuser_x;http://webdav.host/~/pathwill map tofile:///data/homes/user_x/path.
for Rules Process¶
HideFileInDir Object¶
- Introduced in 1.0
- Last updated in 1.0
| Key | Value Type | Default Value | Example |
|---|---|---|---|
| enable | bool | true |
- |
| enable_default_rules | bool | true |
- |
| user_rules | dict | {} |
like default |
GuessTypeExtension Object¶
- Introduced in 0.4
- Last updated in 0.4
| Key | Value Type | Default Value | Example |
|---|---|---|---|
| enable | bool | true |
- |
| enable_default_mapping | bool | true |
- |
| filename_mapping | dict[str, str] | {} |
{"README": "text/plain"} |
| suffix_mapping | dict[str, str] | {} |
{".md": "text/plain"} |
TextFileCharsetDetect Object¶
- Introduced in 0.5
- Last updated in 0.5
| Key | Value Type | Default Value |
|---|---|---|
| enable | bool | false |
| default | str | "utf-8" |
for Response¶
Compression Object¶
- Introduced in 0.5
- Last updated in 1.6
| Key | Value Type | Default Value | Changed | Example |
|---|---|---|---|---|
| enable | bool | true |
v1.6 | - |
| enable_gzip | bool | true |
v0.5 | - |
| enable_zstd | bool | true |
v0.5 | - |
| level | DAVCompressLevel | "recommend" |
v0.5 | "fast"/"recommend"/"best" |
| content_type_user_rule | str | "" |
v0.5 | "^application/xml$|^text/" |
CompressLevel Object¶
- Introduced in 0.5
- Last updated in 1.7
| DAVCompressLevel | Gzip Level | Zstd Level |
|---|---|---|
| fast | 1 | 1 |
| recommend | 4 | 3 |
| best | 9 | 19 |
CORS Object¶
- Introduced in 1.1
- Last updated in 1.1
| Key | Value Type | Default Value | Example |
|---|---|---|---|
| enable | bool | false |
- |
| allow_url_regex | str | None |
^/cors/path |
| allow_origins | list[str] | [] |
["*"] or ["https://example.com","http://localhost"] |
| allow_origin_regex | str | None |
^https://.*\.example\.com$ |
| allow_methods | list[str] | ["GET"] |
- |
| allow_headers | list[str] | [] |
["*"] or ["I-Am-Example-Header,"Me-Too"] |
| allow_credentials | bool | false |
- |
| expose_headers | list[str] | [] |
- |
| preflight_max_age | int | 600 |
- |
logging Object¶
- Introduced in 1.4
- Last updated in 1.4
| Key | Value Type | Default Value |
|---|---|---|
| enable | bool | true |
| level | str | "INFO" |
| display_datetime | bool | true |
| use_colors | bool | true |