webdav

    WebDAV XML/authoring core with HTTP(S), Digest, locks and streaming host

    Download zip
    Version
    0.4.0
    License
    MIT
    Last updated
    4 hours ago
    Downloads
    1

    #可执行 API 示例

    这些例子调用公开 MoonBit API,并随 moon test 执行。HTTP(S) 传输由 Node 宿主提供,使用方式见 README。

    ///|
    test "PROPPATCH escaping and method" {
    let r = @webdav.proppatch("/a b", [("displayname", "A&B<C")])
    assert_eq(r.verb, "PROPPATCH")
    assert_eq(r.target, "/a%20b")
    assert_true(r.body.contains("A&amp;B&lt;C"))
    assert_true(
    try {
    ignore(@webdav.proppatch("/", []))
    false
    } catch {
    _ => true
    },
    )
    }

    ///|
    test "mixed XML properties and lock request" {
    let value = @webdav.parse_xml(
    "<x:note xmlns:x='urn:example' xml:lang='zh'>前<x:b>中</x:b>后</x:note>",
    )
    assert_eq(value.text_content(), "前中后")
    assert_eq(@webdav.parse_xml(value.to_xml()), value)
    let patch = @webdav.set_properties("/文档", [value], [
    ("urn:example", "old"),
    ])
    assert_eq(patch.verb, "PROPPATCH")
    assert_true(patch.body.contains("D:remove"))
    let lock = @webdav.lock_request("/文档", "owner", depth="0")
    assert_eq(lock.verb, "LOCK")
    let refresh = @webdav.refresh_lock("/文档", "urn:uuid:test")
    assert_eq(refresh.headers.get("If"), Some("(<urn:uuid:test>)"))
    }

    XML 保留展开名称、属性和混合内容;不保留原前缀、注释或 PI。拒绝 DTD/外部实体。网络与独立服务器复现见 TESTING.md。

    DavError

    pub suberror DavError {
    Invalid(String)
    } derive(
    Debug
    )

    DavResponse

    pub(all) struct DavResponse {
    hrefs : Array[String]
    status : Int?
    properties : Array[XmlProperty]
    description : String?
    location : String?
    errors : Array[XmlElement]
    } derive(Eq, ToJson,
    Debug
    )

    LockInfo

    pub(all) struct LockInfo {
    token : String?
    root : String?
    owner : XmlElement?
    scope : String
    depth : String
    timeout : String?
    } derive(Eq, ToJson,
    Debug
    )

    Property

    pub(all) struct Property {
    uri : String
    name : String
    value : String
    status : Int
    } derive(Eq, ToJson,
    Debug
    )

    Request

    pub(all) struct Request {
    verb : String
    target : String
    headers : Map[String, String]
    body : String
    } derive(Eq, ToJson,
    Debug
    )

    Resource

    pub(all) struct Resource {
    href : String
    status : Int?
    properties : Array[Property]
    } derive(Eq, ToJson,
    Debug
    )

    XmlAttribute

    pub(all) struct XmlAttribute {
    uri : String
    name : String
    value : String
    } derive(Eq, ToJson,
    Debug
    )

    XmlContent

    pub(all) enum XmlContent {
    Text(String)
    Element(XmlElement)
    } derive(Eq, ToJson,
    Debug
    )

    XmlElement

    pub(all) struct XmlElement {
    uri : String
    name : String
    attributes : Array[XmlAttribute]
    content : Array[XmlContent]
    } derive(Eq, ToJson,
    Debug
    )

    XmlElement::text_content

    fn XmlElement::text_content(self : XmlElement) -> String

    XmlElement::to_xml

    fn XmlElement::to_xml(self : XmlElement) -> String raise DavError

    XmlProperty

    pub(all) struct XmlProperty {
    element : XmlElement
    status : Int
    } derive(Eq, ToJson,
    Debug
    )

    copy_move

    fn copy_move(verb : String, raw_path : String, destination : String, overwrite : Bool) -> Request raise DavError

    if_resources

    fn if_resources(conditions : Array[(String, Array[String])]) -> String raise DavError

    Tagged lists: tokens within one resource list are ANDed. Resource lists are separate conditions.

    if_tokens

    fn if_tokens(tokens : Array[String]) -> String raise DavError

    lock_request

    fn lock_request(raw_path : String, owner : String, depth? : String, timeout? : String, shared? : Bool) -> Request raise DavError

    parse_locks

    fn parse_locks(source : String) -> Array[LockInfo] raise DavError

    parse_multistatus

    fn parse_multistatus(source : String) -> Array[Resource] raise DavError

    Compatibility view; use parse_responses for namespaced XML attributes and mixed content.

    parse_responses

    fn parse_responses(source : String) -> Array[DavResponse] raise DavError

    parse_xml

    fn parse_xml(source : String) -> XmlElement raise DavError

    Bounded XML 1.0 UTF-8 infoset parser. DTD/external entities are deliberately rejected.

    path

    fn path(raw : String) -> String raise DavError

    property_xml

    fn property_xml(name : String, value : String) -> String raise DavError

    propfind

    fn propfind(raw_path : String, depth : Int, properties : Array[String]) -> Request raise DavError

    propfind_names

    fn propfind_names(raw_path : String, depth : Int, properties : Array[(String, String)], names_only? : Bool) -> Request raise DavError

    proppatch

    fn proppatch(raw_path : String, properties : Array[(String, String)]) -> Request raise DavError

    Set DAV properties atomically on the server; this only constructs the request.

    refresh_lock

    fn refresh_lock(raw_path : String, token : String, timeout? : String) -> Request raise DavError

    set_properties

    fn set_properties(raw_path : String, set : Array[XmlElement], remove : Array[(String, String)]) -> Request raise DavError

    unlock_request

    fn unlock_request(raw_path : String, token : String) -> Request raise DavError