WebDavStdClient.authenticated constructor

WebDavStdClient.authenticated({
  1. required WebDavAuthenticationConfig authentication,
  2. HttpClient? client,
  3. Future<ConnectionTask<Socket>> connectionFactory(
    1. Uri uri,
    2. String? proxyHost,
    3. int? proxyPort
    )?,
})

Creates a native WebDAV client with scoped Basic or Digest authentication.

Sets Authorization directly, replacing HttpClient.authenticate and HttpClient.addCredentials for site authentication. Supports mixed server challenges containing Basic. authentication selects automatic discovery or preemptive Basic and limits requests to one origin and directory subtree.

import 'package:simple_webdav_client/client.dart';

final dav = WebDavStdClient.authenticated(
  authentication: WebDavAuthenticationConfig(
    scope: Uri.parse('https://example.com/dav/'),
    username: 'user',
    password: 'app-password',
  ),
);
// Use dav.dispatch(...) and close dav when finished.

For SDK-managed site authentication, use WebDavStdClient.new or WebDavStdClient.withClient with setAuthenticate / addCredentials. With this constructor, supply server credentials in WebDavAuthenticationConfig; both methods throw StateError.

Proxy authentication remains SDK-managed: configure HttpClient.findProxy, setAuthenticateProxy and addProxyCredentials separately. An injected client retains its proxy and TLS settings, must have no SDK site credentials or authentication callback, and is also closed by close.

For custom HTTP Digest connections, supply connectionFactory here. HTTP Digest uses a fresh connection per request; other modes and HTTPS retain the client's connection handling.

Automatic discovery completes before the first business request. An anonymous successful probe keeps requests anonymous; choose an appropriate probe URI or explicit Basic if authentication is needed for the operation. Redirects are returned to the caller, and business requests are not replayed by the package. SDK proxy-authentication retries can omit request bodies. Transport exceptions propagate unchanged. Create a new client to change credentials or rediscover an expired Digest nonce.

Throws UnsupportedError on the Web.

Implementation

WebDavStdClient.authenticated({
  required WebDavAuthenticationConfig authentication,
  HttpClient? client,
  Future<ConnectionTask<Socket>> Function(
    Uri uri,
    String? proxyHost,
    int? proxyPort,
  )?
  connectionFactory,
}) {
  this.client = client ?? HttpClient();
  _authentication = WebDavAuthenticationSession(
    authentication,
    this.client,
    connectionFactory: connectionFactory,
  );
}