Struct PasswordClientBuilder

Source
pub struct PasswordClientBuilder(/* private fields */);
Expand description

Builds a PasswordClient from the supplied challenges; create via PasswordClient::builder.

Often you can just use PasswordClient’s TryFrom implementations to convert from a parsed challenge (crate::ChallengeRef) or unparsed challenges (str, http::header::HeaderValue, or http::header::GetAll).

The builder allows more flexibility. For example, if you are using a HTTP library which is not based on a http crate, you might need to create a PasswordClient from an iterator over multiple WWW-Authenticate headers. You can feed each to PasswordClientBuilder::challenges.

Prefers Digest over Basic, consistent with the RFC 7235 section 2.1 advice for a user-agent to pick the most secure auth-scheme it understands.

When there are multiple Digest challenges, currently uses the first, consistent with the RFC 7616 section 3.7 advice to “use the first challenge it supports, unless a local policy dictates otherwise”. In the future, it may prioritize by algorithm.

Ignores parse errors as long as there’s at least one parseable, supported challenge.

§Example

use http_auth::PasswordClient;
let client = PasswordClient::builder()
    .challenges("UnsupportedSchemeA, Basic realm=\"foo\", UnsupportedSchemeB")
    .challenges("Digest \
                 realm=\"http-auth@example.org\", \
                 qop=\"auth, auth-int\", \
                 algorithm=MD5, \
                 nonce=\"7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v\", \
                 opaque=\"FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS\"")
    .build()
    .unwrap();
assert!(matches!(client, PasswordClient::Digest(_)));

Implementations§

Source§

impl PasswordClientBuilder

Source

pub fn header_value<V: HeaderValue>(self, value: &V) -> Self

Available on crate features http or http10 only.

Considers all challenges from the given http::HeaderValue challenge list.

Source

pub fn challenges(self, value: &str) -> Self

Considers all challenges from the given &str challenge list.

Source

pub fn challenge(self, challenge: &ChallengeRef<'_>) -> Self

Considers a single challenge.

Source

pub fn build(self) -> Result<PasswordClient, String>

Returns a new PasswordClient or fails.

Trait Implementations§

Source§

impl Default for PasswordClientBuilder

Source§

fn default() -> PasswordClientBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V