Skip to main content

Crate diqwest

Crate diqwest 

Source
Expand description

This crate extends reqwest to be able to send requests with digest auth flow.

When you send a request with digest auth flow this first request will be executed. In case the response is a 401 the www-authenticate header is parsed and the answer is calculated. The initial request is executed again with additional Authorization header. The response will be returned from send_digest_auth().

In case the first response is not a 401 this first response is returned from send_digest_auth() without any manipulation. In case the first response is a 401 but the www-authenticate header is missing the first reponse is returned as well.

§Examples

§Simple usage (no caching)

use diqwest::WithDigestAuth;
use reqwest::Client;

let response = Client::new()
  .get("https://example.com/api")
  .send_digest_auth(("username", "password"))
  .await?;

§With session (caching)

Use DigestAuthSession when making multiple requests to the same server to avoid the 401 challenge on subsequent requests:

use diqwest::{WithDigestAuth, DigestAuthSession};
use reqwest::Client;

let client = Client::new();
let session = DigestAuthSession::new("username", "password");

// First request: 401 -> auth -> 200 (credentials cached)
let resp1 = client.get("https://example.com/api")
  .send_digest_auth(&session)
  .await?;

// Subsequent requests: preemptive auth -> 200 (no 401 challenge)
let resp2 = client.get("https://example.com/other")
  .send_digest_auth(&session)
  .await?;

§Blocking

Enable the blocking feature in your Cargo.toml:

use diqwest::blocking::WithDigestAuth;
use reqwest::blocking::Client;

let response = Client::new()
  .get("https://example.com/api")
  .send_digest_auth(("username", "password"))?;

Re-exports§

pub use crate::session::Credentials;
pub use crate::session::DigestAuthCredentials;
pub use crate::session::DigestAuthSession;

Modules§

common
error
session

Traits§

WithDigestAuth
A trait to extend the functionality of an async RequestBuilder to send a request with digest auth flow.