simple_webdav_client
is a Dart WebDAV client with full RFC 4918 support,
including file operations (PUT/GET/CREATE/DELETE/MKCOL/MOVE/COPY),
property management (PROPFIND/PROPUPDATE), and locking (LOCK/UNLOCK).
Ideal for these needing complete WebDAV functionality.
Client's API invocation style is similar to HttpClient
and works more easily with async programming.
refer to here for more exmaples.
Following methods have been implemented:
Used to retrieve properties defined on the resource identified by the Request-URI. see RFC4918#9.1 for more information.
You can make a direct request or use the dispatcher's API to make a request (following related sections will not be repeated).
// openUrl
client.openUrl(
method: WebDavMethod.propfind,
url: url,
// Use [PropfindPropRequestParam] to specify the properties to be requested,
// [PropfindAllRequestParam] to retrieve as many live properties as possible,
// and [PropfindNameRequestParam] to retrieve all property names.
param: PropfindPropRequestParam(...),
);
// api
client.dispatch(url).findProps(...);
client.dispatch(url).findAllProps(...);
client.dispatch(url).findPropNames(...);
Used to set and/or remove properties defined on the resource identified by the request-URI. see RFC4918#9.2 for more information.
// openUrl
client.openUrl(
method: WebDavMethod.propfind,
url: url,
param: ProppatchRequestParam(...),
);
// api
client.dispatch(url).updateProps(...);
Creates new (collection) resource at the location specified by the Request-URI. see RFC4918#9.3 - MKCOL and RFC4918#9.7 - PUT for more information.
// openUrl
client.openUrl(
method: WebDavMethod.propfind,
url: url,
// mkcol: MkcolRequestParam
// put: PutRequestParam
param: MkcolRequestParam(...),
);
// api
client.dispatch(url).create(...);
client.dispatch(url).createDir(...);
Same as the HTTP methods defined in RFC7231.
// openUrl
client.openUrl(
method: WebDavMethod.propfind,
url: url,
// get: GetRequestParam
// head: HeadRequestParam
// post: PostRequestParam
param: GetRequestParam(...),
);
// api: get
client.dispatch(url).get(...);
Deletes resource identified by the Request-URI. see RFC4918#9.6 for more information.
// openUrl
client.openUrl(
method: WebDavMethod.propfind,
url: url,
param: DeleteRequestParam(...),
);
// api
client.dispatch(url).delete(...);
client.dispatch(url).deleteDir(...);
Create a copy of the source resource. see RFC4918#9.8 for more information.
// openUrl
client.openUrl(
method: WebDavMethod.propfind,
url: url,
param: CopyRequestParam(...),
);
// api
client.dispatch(url).copy(...);
client.dispatch(url).copyDir(...);
Move a resource to a new location. see RFC4918#9.9 for more information.
// openUrl
client.openUrl(
method: WebDavMethod.propfind,
url: url,
param: MoveRequestParam(...),
);
// api
client.dispatch(url).move(...);
client.dispatch(url).moveDir(...);
Used to Request lock on a resource. see RFC4918#9.10 for more information.
// openUrl
client.openUrl(
method: WebDavMethod.propfind,
url: url,
param: LockRequestParam(...),
);
// api
client.dispatch(url).createLock(...);
client.dispatch(url).createDirLock(...);
client.dispatch(url).renewLock(...);
Removes the lock identified by the token in Lock-Token. see RFC4918#9.11 for more information.
// openUrl
client.openUrl(
method: WebDavMethod.propfind,
url: url,
param: UnlockRequestParam(...),
);
// api
client.dispatch(url).unlock(...);
Check test cases in dir:intergration_test/methods_test and example/main.dart for more examples.
WebDavClient.std().dispatch(newFilePath)
.findAllProps(includes: [PropfindRequestProp('author', 'CUSTOM:')])
.then((request) => request.close())
.then((response) => response.parse())
.then((result) => print(result?.toDebugString()));
BaseRespResultParser generateParser() {
final propParsers = Map.of(kStdPropParserManager);
propParsers[(name: "author", ns: "CUSTOM:")] = const StringPropParser();
final propstatParser = BasePropstatElementParser(
parserManger: WebDavResposneDataParserManger(parsers: propParsers),
statusParser: const BaseHttpStatusElementParser(),
errorParser: const BaseErrorElementParser());
final responseParser = BaseResponseElementParser(
hrefParser: const BaseHrefElementParser(),
statusParser: const BaseHttpStatusElementParser(),
propstatParser: propstatParser,
errorParser: const BaseErrorElementParser(),
locationParser: const BaseHrefElementParser());
final multistatParser =
BaseMultistatusElementParser(responseParser: responseParser);
final parsers = Map.of(kStdElementParserManager);
parsers[(name: WebDavElementNames.multistatus, ns: kDavNamespaceUrlStr)] =
multistatParser;
return BaseRespResultParser(
singleResDecoder: kStdResponseResultParser.singleResDecoder,
multiResDecoder: BaseRespMultiResultParser(
parserManger: WebDavResposneDataParserManger(parsers: parsers)));
}
final parser = generateParser();
// openUrl
client.openUrl(
method: WebDavMethod.propfind,
url: url,
param: ...,
responseResultParser: parser
);
// dispatch
WebDavClient.std().dispatch(newFilePath, responseResultParser: parser);
MIT License
Copyright (c) 2024 Fries_I23
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.