pub struct CardDavClient<C>{
pub webdav_client: WebDavClient<C>,
}Expand description
Client to communicate with a CardDAV server.
Instances are usually created via CardDavClient::new:
use http::Uri;
use hyper_rustls::HttpsConnectorBuilder;
use hyper_util::{client::legacy::Client, rt::TokioExecutor};
use tower_http::auth::AddAuthorization;
let uri = Uri::try_from("https://example.com").unwrap();
let https_connector = HttpsConnectorBuilder::new()
.with_native_roots()
.unwrap()
.https_or_http()
.enable_http1()
.build();
let https_client = Client::builder(TokioExecutor::new()).build(https_connector);
let https_client = AddAuthorization::basic(https_client, "user", "secret");
let webdav = WebDavClient::new(uri, https_client);
let client = CardDavClient::new(webdav);If the real CardDAV server needs to be resolved via automated service discovery, use
CardDavClient::bootstrap_via_service_discovery.
For setting the Authorization header or applying other changes to outgoing requests, see the
documentation on WebDavClient.
Fields§
§webdav_client: WebDavClient<C>A WebDAV client used to send requests.
Implementations§
Source§impl<C> CardDavClient<C>
impl<C> CardDavClient<C>
Sourcepub fn new(webdav_client: WebDavClient<C>) -> CardDavClient<C>
pub fn new(webdav_client: WebDavClient<C>) -> CardDavClient<C>
Sourcepub async fn bootstrap_via_service_discovery(
webdav_client: WebDavClient<C>,
) -> Result<CardDavClient<C>, BootstrapError>
pub async fn bootstrap_via_service_discovery( webdav_client: WebDavClient<C>, ) -> Result<CardDavClient<C>, BootstrapError>
Automatically bootstrap a new client instance.
Creates a new client, with its base_url set to the context path retrieved using service
discovery via find_context_url.
§Errors
Returns an error if:
- The URL has an invalid schema.
- The underlying call to
find_context_urlreturns an error.
Methods from Deref<Target = WebDavClient<C>>§
Sourcepub fn relative_uri(&self, path: &str) -> Result<Uri, Error>
pub fn relative_uri(&self, path: &str) -> Result<Uri, Error>
Returns a new URI relative to the server’s root.
path MUST NOT be percent-encoded, except for any reserved characters.
§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<C::Error>>
pub async fn find_current_user_principal( &self, ) -> Result<Option<Uri>, FindCurrentUserPrincipalError<C::Error>>
Resolves the current user’s principal resource.
First queries the base_url, then the root path on the same host.
Returns None if the response’s status code is 404 or if no principal was found.
§Errors
See FindCurrentUserPrincipalError
§See also
The DAV:current-user-principal property is defined in
https://www.rfc-editor.org/rfc/rfc5397#section-3
Sourcepub async fn request_raw(
&self,
request: Request<String>,
) -> Result<(Parts, Bytes), RequestError<C::Error>>
pub async fn request_raw( &self, request: Request<String>, ) -> Result<(Parts, Bytes), RequestError<C::Error>>
Send a raw request to the server.
Sends a request, applying any necessary authentication and logging the response.
This is a lower-level API. Prefer using WebDavClient::request with the Requests API
instead.
§Errors
Returns an error if the underlying http request fails or if streaming the response fails.
Sourcepub async fn find_context_path(
&self,
service: DiscoverableService,
host: &str,
port: u16,
) -> Result<Option<Uri>, ResolveContextPathError<C::Error>>
pub async fn find_context_path( &self, service: DiscoverableService, host: &str, port: u16, ) -> Result<Option<Uri>, ResolveContextPathError<C::Error>>
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
Locationheader in the response is missing or invalid.
§See also
Sourcepub async fn request<R>(
&self,
request: R,
) -> Result<R::Response, R::Error<C::Error>>where
R: DavRequest,
R::Error<C::Error>: From<Error> + From<RequestError<C::Error>> + From<R::ParseError>,
pub async fn request<R>(
&self,
request: R,
) -> Result<R::Response, R::Error<C::Error>>where
R: DavRequest,
R::Error<C::Error>: From<Error> + From<RequestError<C::Error>> + From<R::ParseError>,
Execute a typed DAV request.
Provides a type-safe way to execute WebDAV operations using typed requests and response
types. Each request type implements the crate::requests::DavRequest trait, and can
therefore:
- Serialise itself into an HTTP request.
- Parse the HTTP response into a typed response.
§Example
use libdav::dav::GetEtag;
let response = webdav.request(
GetEtag::new("/calendar/event.ics")
).await?;
println!("Etag: {}", response.etag);§Errors
Returns an error if:
- The request cannot be prepared (e.g., invalid parameters).
- The HTTP request fails.
- The response cannot be parsed.
Trait Implementations§
Source§impl<C> Clone for CardDavClient<C>
impl<C> Clone for CardDavClient<C>
Source§fn clone(&self) -> CardDavClient<C>
fn clone(&self) -> CardDavClient<C>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more