Skip to content

Commit

Permalink
remove http dependency, use transitive from reqwest
Browse files Browse the repository at this point in the history
  • Loading branch information
maoertel committed Oct 14, 2021
1 parent 408d507 commit f541d9c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.1.2

- get rid of explicit `http 0.2` dependency and use it transitive from `reqwest`

# 0.1.1

- make the dependencies less restrictive
Expand Down
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "diqwest"
version = "0.1.1"
version = "0.1.2"
edition = "2018"
authors = ["Mathias Oertel <mathias.oertel@pm.me>"]
description = "Trait to extend reqwest for digest auth flow."
Expand All @@ -14,5 +14,4 @@ repository = "https://github.com/maoertel/diqwest"
[dependencies]
async-trait = "0.1"
digest_auth = "0.3"
http = "0.2"
reqwest = "0.11"
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ This crate extends `reqwest` to be able to send requests with digest auth flow.

It is currently implemented for `async` usage only.

When you send the 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_with_digest_auth()`.

In case the first response is not a `401` this first response is returned from `send_with_digest_auth()` without any manipulation.

## Example
```rust
use diqwest::core::WithDigestAuth;
use reqwest::{Client, Response};

// Call `.send_with_basic_auth()` at the end of your request builder chain like you would use `send()`
// Call `.send_with_digest_auth()` on `RequestBuilder` like `send()`
let response: Response = Client::new()
.get("url")
.send_with_digest_auth("username", "password")
Expand Down
5 changes: 2 additions & 3 deletions src/core.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use async_trait::async_trait;
use digest_auth::{AuthContext, HttpMethod};
use http::StatusCode;
use reqwest::{RequestBuilder, Response};
use reqwest::{RequestBuilder, Response, StatusCode};

use Error::RequestBuilderNotCloneableError;

Expand Down Expand Up @@ -30,7 +29,7 @@ impl WithDigestAuth for RequestBuilder {
let method = HttpMethod::from(request.method().as_str());
let body = request.body().and_then(|b| b.as_bytes());
let answer =
DigestAuthHelper::parse_digest_auth_header(first_response, url.as_str(), method, body, username, password)?;
DigestAuthHelper::parse_digest_auth_header(first_response, url.as_str(), method, body, username, password)?;

Ok(clone_request_builder(self)?.header("Authorization", answer).send().await?)
}
Expand Down
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::{Debug, Display, Formatter};
use std::result;

use http::header::ToStrError;
use reqwest::header::ToStrError;

use Error::RequestBuilderNotCloneableError;

Expand All @@ -11,7 +11,7 @@ use crate::error::Error::{DigestAuthError, ReqwestError, ToStrError as MyToStrEr
pub enum Error {
ReqwestError(reqwest::Error),
DigestAuthError(digest_auth::Error),
ToStrError(http::header::ToStrError),
ToStrError(reqwest::header::ToStrError),
RequestBuilderNotCloneableError,
}

Expand Down Expand Up @@ -42,7 +42,7 @@ impl From<digest_auth::Error> for Error {
}
}

impl From<http::header::ToStrError> for Error {
impl From<reqwest::header::ToStrError> for Error {
fn from(e: ToStrError) -> Self {
MyToStrError(e)
}
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
//!
//! It is currently implemented for async usage only.
//!
//! When you send the 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_with_digest_auth()`.
//!
//! In case the first response is not a `401` this first response is returned from
//! `send_with_digest_auth()` without any manipulation.
//!
//! # Example
//!
//! Usage:
Expand Down

0 comments on commit f541d9c

Please sign in to comment.