diff --git a/Cargo.toml b/Cargo.toml index c623704..6da8622 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ rustls-tls = ["reqwest/rustls-tls"] async-trait = "0.1" digest_auth = "0.3" reqwest = { version = "0.11", default-features = false } +url = "2.3" [dev-dependencies] tokio = { version = "1", features = ["full"] } diff --git a/src/blocking.rs b/src/blocking.rs index 061be24..9926b5d 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -1,6 +1,7 @@ use digest_auth::HttpMethod; use reqwest::blocking::{RequestBuilder, Response}; use reqwest::StatusCode; +use url::Position; use crate::error::Error::{AuthHeaderMissing, RequestBuilderNotCloneable}; use crate::error::Result; @@ -23,7 +24,7 @@ impl WithDigestAuth for RequestBuilder { match first_response.status() { StatusCode::UNAUTHORIZED => { let request = clone_request_builder(self)?.build()?; - let path = request.url().path(); + let path = &request.url()[Position::AfterPort..]; let method = HttpMethod::from(request.method().as_str()); let body = request.body().and_then(|b| b.as_bytes()); let answer = parse_digest_auth_header(first_response.headers(), path, method, body, username, password); @@ -105,7 +106,7 @@ mod tests { .with_status(200) .create(); - let request = Client::new().get(&url); + let request = Client::new().get(url); // When I send with digest auth let response = request.send_with_digest_auth("username", "password").unwrap(); diff --git a/src/lib.rs b/src/lib.rs index a431830..6529fea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,6 +48,7 @@ use digest_auth::{AuthContext, AuthorizationHeader, HttpMethod}; use error::Error; use reqwest::header::HeaderMap; use reqwest::{RequestBuilder, Response, StatusCode}; +use url::Position; use crate::error::Error::RequestBuilderNotCloneable; use crate::error::Result; @@ -71,7 +72,7 @@ impl WithDigestAuth for RequestBuilder { match first_response.status() { StatusCode::UNAUTHORIZED => { let request = clone_request_builder(self)?.build()?; - let path = request.url().path(); + let path = &request.url()[Position::AfterPort..]; let method = HttpMethod::from(request.method().as_str()); let body = request.body().and_then(|b| b.as_bytes()); let answer = parse_digest_auth_header(first_response.headers(), path, method, body, username, password);