Struct libdav::dav::WebDavClient
source · pub struct WebDavClient<C>{
pub base_url: Uri,
/* private fields */
}
Expand description
A webdav client.
The generic parameter C
defines what kind of connector is used to establish new connections.
Fields§
§base_url: Uri
Base URL to be used for all requests.
This is composed of the domain+port used for the server, plus the context path where Dav requests are served.
Implementations§
source§impl<C> WebDavClient<C>
impl<C> WebDavClient<C>
sourcepub fn new(base_url: Uri, auth: Auth, connector: C) -> WebDavClient<C>
pub fn new(base_url: Uri, auth: Auth, connector: C) -> WebDavClient<C>
Builds a new webdav client.
Only https
is enabled by default. Plain-text http
is only enabled if the
input uri has a scheme of http
or caldav
.
sourcepub fn relative_uri(&self, path: impl AsRef<str>) -> Result<Uri, Error>
pub fn relative_uri(&self, path: impl AsRef<str>) -> Result<Uri, Error>
Returns a new URI relative to the server’s root.
§Errors
If this client’s base_url
is invalid or the provided path
is not an acceptable path.
sourcepub async fn find_current_user_principal(
&self,
) -> Result<Option<Uri>, FindCurrentUserPrincipalError>
pub async fn find_current_user_principal( &self, ) -> Result<Option<Uri>, FindCurrentUserPrincipalError>
Resolves the current user’s principal resource.
Returns None
if the response’s status code is 404 or if no principal was found.
§Errors
- If the underlying HTTP request fails.
- If the response status code is neither success nor 404.
- If parsing the XML response fails.
- If the
href
cannot be parsed into a validUri
§See also
sourcepub async fn propfind(
&self,
url: &Uri,
properties: &[&PropertyName<'_, '_>],
depth: u8,
) -> Result<(Parts, Bytes), WebDavError>
pub async fn propfind( &self, url: &Uri, properties: &[&PropertyName<'_, '_>], depth: u8, ) -> Result<(Parts, Bytes), WebDavError>
Sends a PROPFIND
request.
This is a shortcut for simple PROPFIND
requests.
§Errors
If there are any network errors.
sourcepub async fn request(
&self,
request: Request<String>,
) -> Result<(Parts, Bytes), RequestError>
pub async fn request( &self, request: Request<String>, ) -> Result<(Parts, Bytes), RequestError>
Send a request to the server.
Sends a request, applying any necessary authentication and logging the response.
§Errors
Returns an error if the underlying http request fails or if streaming the response fails.
sourcepub async fn get_property(
&self,
href: &str,
property: &PropertyName<'_, '_>,
) -> Result<Option<String>, WebDavError>
pub async fn get_property( &self, href: &str, property: &PropertyName<'_, '_>, ) -> Result<Option<String>, WebDavError>
Fetch a single property.
§Common properties
names::ADDRESSBOOK_DESCRIPTION
names::CALENDAR_COLOUR
names::CALENDAR_DESCRIPTION
names::CALENDAR_ORDER
names::DISPLAY_NAME
§Quirks
The namespace of the value in the response from the server is ignored. This is a workaround
for an issue in cyrus-imapd
.
§Errors
- If there are any network errors or the response could not be parsed.
- If the requested property is missing in the response.
§See also
sourcepub async fn get_properties<'p>(
&self,
href: &str,
properties: &[&PropertyName<'p, 'p>],
) -> Result<Vec<(PropertyName<'p, 'p>, Option<String>)>, WebDavError>
pub async fn get_properties<'p>( &self, href: &str, properties: &[&PropertyName<'p, 'p>], ) -> Result<Vec<(PropertyName<'p, 'p>, Option<String>)>, WebDavError>
Fetch multiple properties for a single resource.
Values in the returned Vec
are in the same order as the properties
parameter.
§Quirks
Same as WebDavClient::get_property
.
§Errors
- If there are any network errors or the response could not be parsed.
- If the requested property is missing in the response.
§See also
sourcepub async fn set_property(
&self,
href: &str,
property: &PropertyName<'_, '_>,
value: Option<&str>,
) -> Result<Option<String>, WebDavError>
pub async fn set_property( &self, href: &str, property: &PropertyName<'_, '_>, value: Option<&str>, ) -> Result<Option<String>, WebDavError>
Sends a PROPUPDATE
query to the server.
Setting the value to None
will remove the property. Returns the new value as returned by
the server.
§Quirks
Same as WebDavClient::get_property
.
§Errors
If there are any network errors or the response could not be parsed.
§See also
WebDavClient::get_property
(contains a list of some included well-known properties)
sourcepub async fn find_context_path(
&self,
service: DiscoverableService,
host: &str,
port: u16,
) -> Result<Option<Uri>, ResolveContextPathError>
pub async fn find_context_path( &self, service: DiscoverableService, host: &str, port: u16, ) -> Result<Option<Uri>, ResolveContextPathError>
Resolve the default context path using a well-known path.
This only applies for servers supporting webdav extensions like caldav or carddav. Returns
Ok(None)
if the well-known path does not redirect to another location.
§Errors
- If the provided scheme, host and port cannot be used to construct a valid URL.
- If there are any network errors.
- If the response is not an HTTP redirection.
- If the
Location
header in the response is missing or invalid.
§See also
sourcepub async fn list_resources(
&self,
collection_href: &str,
) -> Result<Vec<ListedResource>, WebDavError>
pub async fn list_resources( &self, collection_href: &str, ) -> Result<Vec<ListedResource>, WebDavError>
Enumerates resources in a collection
§Errors
If there are any network errors or the response could not be parsed.
sourcepub async fn create_resource(
&self,
href: impl AsRef<str>,
data: Vec<u8>,
mime_type: impl AsRef<[u8]>,
) -> Result<Option<String>, WebDavError>
pub async fn create_resource( &self, href: impl AsRef<str>, data: Vec<u8>, mime_type: impl AsRef<[u8]>, ) -> Result<Option<String>, WebDavError>
Creates a new resource
Returns an Etag
if present in the response. If the Etag
is not included, it must be
requested in a follow-up request, and cannot be obtained race-free.
§Errors
If there are any network errors or the response could not be parsed.
sourcepub async fn update_resource(
&self,
href: impl AsRef<str>,
data: Vec<u8>,
etag: impl AsRef<str>,
mime_type: impl AsRef<[u8]>,
) -> Result<Option<String>, WebDavError>
pub async fn update_resource( &self, href: impl AsRef<str>, data: Vec<u8>, etag: impl AsRef<str>, mime_type: impl AsRef<[u8]>, ) -> Result<Option<String>, WebDavError>
Updates an existing resource
Returns an Etag
if present in the response. If the Etag
is not included, it must be
requested in a follow-up request, and cannot be obtained race-free.
§Errors
If there are any network errors or the response could not be parsed.
sourcepub async fn create_collection(
&self,
href: impl AsRef<str>,
resourcetypes: &[&PropertyName<'_, '_>],
) -> Result<(), WebDavError>
pub async fn create_collection( &self, href: impl AsRef<str>, resourcetypes: &[&PropertyName<'_, '_>], ) -> Result<(), WebDavError>
Creates a collection under path href
.
This function executes an Extended MKCOL.
Additional resource types may be specified via the resourcetypes
argument. The
DAV:collection
resource type is implied and MUST NOT be specified.
§Errors
If there are any network errors or the response could not be parsed.
sourcepub async fn delete(
&self,
href: impl AsRef<str>,
etag: impl AsRef<str>,
) -> Result<(), WebDavError>
pub async fn delete( &self, href: impl AsRef<str>, etag: impl AsRef<str>, ) -> Result<(), WebDavError>
Deletes the resource at href
.
The resource MAY be a collection. Because the implementation for deleting resources and collections is identical, this same function is used for both cases.
If the Etag does not match (i.e.: if the resource has been altered), the operation will fail and return an Error.
§Errors
If there are any network errors or the response could not be parsed.
sourcepub async fn force_delete(
&self,
href: impl AsRef<str>,
) -> Result<(), WebDavError>
pub async fn force_delete( &self, href: impl AsRef<str>, ) -> Result<(), WebDavError>
Force deletion of the resource at href
.
This function does not guarantee that a resource or collection has not been modified since it was last read. Use this function with care.
The resource MAY be a collection. Because the implementation for deleting resources and collections is identical, this same function covers both cases.
§Errors
If there are any network errors or the response could not be parsed.
Trait Implementations§
source§impl<C> Clone for WebDavClient<C>
impl<C> Clone for WebDavClient<C>
source§fn clone(&self) -> WebDavClient<C>
fn clone(&self) -> WebDavClient<C>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl<C> !Freeze for WebDavClient<C>
impl<C> !RefUnwindSafe for WebDavClient<C>
impl<C> Send for WebDavClient<C>
impl<C> Sync for WebDavClient<C>
impl<C> Unpin for WebDavClient<C>where
C: Unpin,
impl<C> !UnwindSafe for WebDavClient<C>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)