Sign in

    q2316367743/webdav/types does not have a README file

    WebdavError

    pub(all) suberror WebdavError {
    WebdavError(WebdavErrorDetail)
    }

    所有 WebDAV 操作的统一错误(单构造器包装,MoonBit 错误类型约定)。 用 detail() 取出分类后模式匹配,to_string() 得中文人读描述。
    impl Show for WebdavError

    WebdavError::api

    fn WebdavError::api(status~ : Int, operation~ : String, message~ : String) -> WebdavError

    构造「非期望状态码」错误。

    WebdavError::cancelled

    fn WebdavError::cancelled(reason? : String) -> WebdavError

    构造「请求已取消」错误。

    WebdavError::detail

    取出错误分类。

    WebdavError::http

    包装网络 / HTTP 协议层错误。

    WebdavError::io

    fn WebdavError::io(message~ : String) -> WebdavError

    构造「本地文件系统错误」:打开 / 读取 / 创建 / 写入本地文件失败时使用, 与 HTTP 层错误区分开(本地问题不该被当成服务端问题排查)。

    WebdavError::output

    fn WebdavError::output(self : WebdavError, logger : &Logger) -> Unit

    WebdavError::partial

    fn WebdavError::partial(operation~ : String, failures~ : Array[ResourceFailure]) -> WebdavError

    构造「部分失败」错误:批量操作(COPY / MOVE / DELETE)的 207 响应里 有资源没成功,failures 至少含一条。

    WebdavError::to_string

    fn WebdavError::to_string(self : WebdavError) -> String

    人读的中文错误描述,便于日志与字符串插值。

    WebdavError::xml

    包装 XML 解析错误。

    ActiveLock

    pub(all) struct ActiveLock {
    token : String
    scope : LockScope
    depth : String?
    owner : String?
    timeout : String?
    lockroot : String?
    }

    一条活动锁(RFC 4918 §14.11 activelock)。

    ByteRange

    pub struct ByteRange {
    start : Int
    end : Int?
    }

    HTTP 字节区间(RFC 7233):字节从 0 计,end 为含端。 只能经 ByteRange::from / ByteRange::suffix 构造,保证取值合法: 后缀形式(取资源末尾 N 字节)以负数 start = -N 存储。

    ByteRange::from

    fn ByteRange::from(start? : Int, end? : Int) -> ByteRange

    区间下载:start 缺省 0;end 省略表示到资源末尾(bytes=start-), 提供则是闭区间(bytes=start-end,两端都含)。

    ByteRange::header_value

    fn ByteRange::header_value(self : ByteRange) -> String

    渲染成 Range 请求头的值:bytes=start-end / bytes=start- / bytes=-length(后缀形式)。

    ByteRange::suffix

    fn ByteRange::suffix(length : Int) -> ByteRange

    后缀区间:取资源末尾 length 个字节(bytes=-length), length 应为正数。

    Conditions

    pub(all) struct Conditions {
    if_match : String?
    if_none_match : String?
    lock_token : String?
    if_lists : Array[IfList]
    }

    条件请求:If-Match / If-None-Match / If,前者取值是服务端给出的 ETag(含引号,原样透传)或通配符 *,用于乐观并发控制; lock_token 是要随请求提交的锁令牌,渲染成 If: (<令牌>) (RFC 4918 §10.4.1 的无标签列表形态);if_lists 是显式的 If 列表, 覆盖多令牌析取、Not / ETag 形态与带标签(</url> (<令牌>))的条件。

    Conditions::new

    fn Conditions::new(if_match? : String, if_none_match? : String, lock_token? : String, if_lists? : Array[IfList]) -> Conditions

    按需构造条件:字段都可省略,省略即不发送对应请求头。 lock_token 可带或不带外层 <>,由 normalize_lock_token 统一形状; 归一化后为空串时视为未设置(不会发出 If: () 这种坏头)。 if_lists 省略时不追加显式 If 列表。

    Conditions::with_lock_token

    fn Conditions::with_lock_token(self : Conditions, token : String) -> Conditions

    换一个锁令牌(其余字段不变):按 423 自动重试时用它把覆盖锁的令牌 补进 If 头。

    ContentRange

    pub(all) struct ContentRange {
    first : Int
    last : Int
    total : Int?
    }

    206(部分内容)响应 Content-Range 头的解析结果: bytes first-last/total,描述服务器实际返回的区间。

    Depth

    pub(all) enum Depth {
    Zero
    One
    Infinity
    }

    Depth 头取值(RFC 4918 §10.2):PROPFIND 的作用深度与 COPY 的 是否浅拷贝都由它表达。

    Depth::to_header

    fn Depth::to_header(self : Depth) -> String

    渲染为 HTTP 头文本:"0" / "1" / "infinity"。

    FileInfo

    pub(all) struct FileInfo {
    href : String
    name : String
    is_dir : Bool
    content_length : Int?
    content_type : String?
    last_modified : String?
    created : String?
    etag : String?
    }

    PROPFIND 解析出的资源条目(文件或目录)。

    GetResult

    pub(all) struct GetResult {
    content : Bytes
    status : Int
    content_type : String?
    content_length : Int?
    etag : String?
    last_modified : String?
    content_range : ContentRange?
    }

    get_file 的结果:内容与响应元数据。

    IfCondition

    pub(all) struct IfCondition {
    kind : IfConditionKind
    value : String
    negated : Bool
    }

    If 头里的一条条件,可带 Not 取反。

    IfCondition::etag

    fn IfCondition::etag(value : String, negated? : Bool) -> IfCondition

    构造 ETag 条件;value 是含引号的 ETag 原文(如 "\"abc\"")。

    IfCondition::token

    fn IfCondition::token(value : String, negated? : Bool) -> IfCondition

    构造状态令牌条件;value 可带或不带外层 <>,渲染时统一只包一层, 归一化后为空串视为无效(渲染成空列表的请求会被本地拦下)。

    IfConditionKind

    pub(all) enum IfConditionKind {
    StateToken
    EntityTag
    }

    If 头里一条条件的作用对象(RFC 4918 §10.4.2): 状态令牌(<令牌>,锁令牌属于此类)或 ETag([etag])。

    IfList

    pub(all) struct IfList {
    resource_tag : String?
    conditions : Array[IfCondition]
    }

    If 头里的一个列表:(<条件> …),可选带资源标签(</url> (<条件>))。 同一列表内的条件是合取;多个列表之间是析取(RFC 4918 §10.4.3)。

    IfList::new

    fn IfList::new(conditions : Array[IfCondition], resource_tag? : String) -> IfList

    按需构造 If 列表:resource_tag 省略时渲染成作用于目标 URL 的 无标签列表。

    LockResult

    pub(all) struct LockResult {
    status : Int
    created : Bool
    lock : ActiveLock
    }

    LOCK(申请或刷新)的响应结果。

    LockScope

    pub(all) enum LockScope {
    Exclusive
    Shared
    }

    锁作用域(RFC 4918 §14.11 lockscope):独占写锁或共享写锁。

    LockScope::from_dav

    fn LockScope::from_dav(name : String) -> LockScope

    解析 lockscope 子元素名(去空白、大小写不敏感): "shared" → Shared,其余(含空串与未知值)→ Exclusive, 与「服务端没给 lockscope 时按独占处理」的既有口径一致。

    LockScope::to_dav

    fn LockScope::to_dav(self : LockScope) -> String

    渲染为 lockscope 子元素名:"exclusive" / "shared"。

    Progress

    pub(all) struct Progress {
    loaded : Int
    total : Int?
    }

    传输进度快照,由上传 / 下载回调接收。

    Progress::percent

    fn Progress::percent(self : Progress) -> Double?

    完成比例 0.0 ~ 1.0;总长未知或为零时为 None。

    PropResult

    pub(all) struct PropResult {
    name : String
    value : String
    status : Int
    }

    属性级读取结果:status 是该属性所在 propstat 的状态码, 404 表示「服务端没有这个属性」,与「属性值为空串」区分开。

    PutResult

    pub(all) struct PutResult {
    status : Int
    created : Bool
    etag : String?
    last_modified : String?
    location : String?
    }

    put_file 的结果。

    ResourceFailure

    pub(all) struct ResourceFailure {
    href : String
    status : Int
    message : String
    }

    部分失败条目:207 Multi-Status 中非 2xx 的那个资源。

    ServerCapabilities

    pub(all) struct ServerCapabilities {
    dav_class : Array[Int]
    allow : Array[String]
    server : String?
    }

    OPTIONS 能力探测结果(DAV / Allow / Server 头)。

    ServerCapabilities::has_lock

    fn ServerCapabilities::has_lock(self : ServerCapabilities) -> Bool

    是否具备 Class 2 作品锁能力(DAV 等级含 2,或 Allow 含 LOCK)。

    ServerCapabilities::supports

    fn ServerCapabilities::supports(self : ServerCapabilities, http_method : String) -> Bool

    服务端是否声明支持某方法(比较 Allow 列表,ASCII 大小写不敏感)。

    WebdavConfig

    pub(all) struct WebdavConfig {
    base_url : String
    username : String?
    password : String?
    timeout_ms : Int?
    retry_on_423 : Bool?
    } derive(Default)

    客户端配置,字段可直接构造,未填字段取 Default(None / 超时默认值)。

    • base_url:服务器根地址,如 "http://127.0.0.1:8080/dav/", 末尾多余的 / 会被内部规范化容忍;
    • username / password:Basic Auth 凭据,均为 None 时不携带认证;
    • timeout_ms:单请求超时毫秒数,None 时取 DEFAULT_TIMEOUT_MS;
    • retry_on_423:写请求被 423(资源被锁定)拒绝、且本客户端自己持有一把 覆盖该路径的锁时,是否用这把锁的令牌自动重试一次;None / false 时保持「不自动重试」的默认行为。

    WebdavConfig::default

    fn WebdavConfig::default() -> WebdavConfig

    WebdavErrorDetail

    pub(all) enum WebdavErrorDetail {
    Http(
    HttpError
    )
    Xml(
    XmlError
    )
    Api(status~ : Int, operation~ : String, message~ : String)
    Partial(operation~ : String, failures~ : Array[ResourceFailure])
    Cancelled(String?)
    Io(message~ : String)
    }

    错误分类:可按「该怎么处理」分支。

    DEFAULT_TIMEOUT_MS

    let DEFAULT_TIMEOUT_MS : Int

    默认单请求超时:30 秒。

    ascii_upper

    fn ascii_upper(text : String) -> String

    ASCII 大写化:HTTP 方法名与 DAV 等级都是 ASCII 文本,够用且不引入依赖。

    href_to_path

    fn href_to_path(href : String) -> String

    把 207 响应里的 href 归一化成服务器上的绝对路径,供「与服务端路径比对」 与「用作本地路径」两种用途:

    • 剥离 scheme://authority(部分服务端与反向代理会回绝对 URL);
    • 丢弃 ?query 与 #fragment;
    • percent 解码;
    • 去掉末尾斜杠(根路径 / 保留)。

    normalize_lock_token

    fn normalize_lock_token(token : String) -> String

    归一化锁令牌:去掉两侧空白与可选的外层 <>。

    令牌在协议里是不透明串(RFC 4918 §6.4):常见形式是 opaquelocktoken:...,但服务端也可能回裸串(hacdias/webdav 就回 裸数字),所以这里不校验 URI 形式,只统一形状。 Lock-Token 响应头自带尖括号,请求里传入的则通常不带, 两种输入经这里归一后都变成不带尖括号的裸令牌。

    parse_ascii_int

    fn parse_ascii_int(text : String) -> Int?

    解析纯 ASCII 数字文本(如 Content-Length、getcontentlength)。 空串、含非数字字符时返回 None。

    parse_content_range

    fn parse_content_range(text : String) -> ContentRange?

    解析 206 响应的 Content-Range 头。RFC 写法为 bytes 0-1/2(空格), 部分实现写 bytes=0-1/2(等号),均容忍;形态不符 / 数字非法 返回 None(bytes */total 形态属于 416 响应,用 parse_unsatisfied_range_total 解析)。

    parse_unsatisfied_range_total

    fn parse_unsatisfied_range_total(text : String) -> Int?

    解析 416 响应的 Content-Range: bytes */total(服务器告知资源总长)。 形态不符时返回 None。

    percent_decode

    fn percent_decode(text : String) -> String

    解码 percent 编码的字符串(如 PROPFIND 返回的 href)。 非法转义序列原样保留;解码结果按 UTF-8 还原,失败时保守返回原文。

    percent_encode_path

    fn percent_encode_path(path : String) -> String

    把路径按 RFC 3986 做 percent 编码:保留 / 与 unreserved 字符, 其余(空格、中文、?、# 等保留 / 分隔字符)逐 UTF-8 字节编码为 %XX。 注意空格编码为 %20 而非表单的 +。