Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove async-trait #20

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ default = []
blocking = ["reqwest/blocking"]

[dependencies]
async-trait = "0.1"
digest_auth = { version = "0.3", default-features = false }
reqwest = { version = "0.12", default-features = false }
url = "2.4"
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ When you send a request with digest auth flow this first request will be execute

In case the first response is not a `401` this first response is returned from `send_with_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.

`diqwest` is a lean crate and has nearly no dependencies:
- `reqwest`, for sure, as `diqwest` is an extension to it. Without any enabled features and no default features.
- `digest_auth` is used to calculate the answer. Without any enabled feature and no default features.
- `url` is used to parse parse a url on type level. Without any enabled feature and no default features.

That's it. No other dependencies are used. Not even `thiserror` is used to not force it on you.

## Examples

### Async (default)
Expand Down
1 change: 1 addition & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ where
fn body(&self) -> Option<&B>;
}

#[allow(dead_code)]
pub(crate) trait WithHeaders {
fn headers(&self) -> &HeaderMap;
}
Expand Down
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ pub mod blocking;
pub mod common;
pub mod error;

use async_trait::async_trait;
use std::future::Future;

use digest_auth::AuthContext;
use reqwest::header::{HeaderMap, AUTHORIZATION};
use reqwest::{Body, Method};
Expand All @@ -57,12 +58,10 @@ use crate::error::{Error, Result};
/// A trait to extend the functionality of an async `RequestBuilder` to send a request with digest auth flow.
///
/// Call it at the end of your `RequestBuilder` chain like you would use `send()`.
#[async_trait]
pub trait WithDigestAuth {
async fn send_with_digest_auth(&self, username: &str, password: &str) -> Result<Response>;
fn send_with_digest_auth(&self, username: &str, password: &str) -> impl Future<Output = Result<Response>> + Send;
}

#[async_trait]
impl WithDigestAuth for RequestBuilder {
async fn send_with_digest_auth(&self, username: &str, password: &str) -> Result<Response> {
let first_response = self.refresh()?.send().await?;
Expand Down
Loading