webdav

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

    Download zip
    Version
    0.4.2
    License
    MIT
    Last updated
    5 hours ago
    Downloads
    3

    #可执行 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
    )

    DavError::to_repr

    DavResponse

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

    DavResponse::equal

    fn DavResponse::equal(DavResponse, DavResponse) -> Bool

    DavResponse::not_equal

    fn DavResponse::not_equal(x : DavResponse, y : DavResponse) -> Bool

    DavResponse::to_json

    fn DavResponse::to_json(DavResponse) -> Json

    LockInfo

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

    LockInfo::equal

    fn LockInfo::equal(LockInfo, LockInfo) -> Bool

    LockInfo::not_equal

    fn LockInfo::not_equal(x : LockInfo, y : LockInfo) -> Bool

    LockInfo::to_json

    fn LockInfo::to_json(LockInfo) -> Json

    LockInfo::to_repr

    Property

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

    Property::equal

    fn Property::equal(Property, Property) -> Bool

    Property::not_equal

    fn Property::not_equal(x : Property, y : Property) -> Bool

    Property::to_json

    fn Property::to_json(Property) -> Json

    Property::to_repr

    Request

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

    Request::equal

    fn Request::equal(Request, Request) -> Bool

    Request::not_equal

    fn Request::not_equal(x : Request, y : Request) -> Bool

    Request::to_json

    fn Request::to_json(Request) -> Json

    Request::to_repr

    Resource

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

    Resource::equal

    fn Resource::equal(Resource, Resource) -> Bool

    Resource::not_equal

    fn Resource::not_equal(x : Resource, y : Resource) -> Bool

    Resource::to_json

    fn Resource::to_json(Resource) -> Json

    Resource::to_repr

    XmlAttribute

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

    XmlAttribute::equal

    XmlAttribute::not_equal

    fn XmlAttribute::not_equal(x : XmlAttribute, y : XmlAttribute) -> Bool

    XmlAttribute::to_json

    XmlContent

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

    XmlContent::equal

    fn XmlContent::equal(XmlContent, XmlContent) -> Bool

    XmlContent::not_equal

    fn XmlContent::not_equal(x : XmlContent, y : XmlContent) -> Bool

    XmlContent::to_json

    fn XmlContent::to_json(XmlContent) -> Json

    XmlElement

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

    XmlElement::equal

    fn XmlElement::equal(XmlElement, XmlElement) -> Bool

    XmlElement::not_equal

    fn XmlElement::not_equal(x : XmlElement, y : XmlElement) -> Bool

    XmlElement::text_content

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

    XmlElement::to_json

    fn XmlElement::to_json(XmlElement) -> Json

    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
    )

    XmlProperty::equal

    fn XmlProperty::equal(XmlProperty, XmlProperty) -> Bool

    XmlProperty::not_equal

    fn XmlProperty::not_equal(x : XmlProperty, y : XmlProperty) -> Bool

    XmlProperty::to_json

    fn XmlProperty::to_json(XmlProperty) -> Json

    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